commonlib
lock_guard.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "memory.h"
14 #include <mutex>
15 
16 BEGIN_NAMESPACE_MEMORY
17 
18 struct UseLock
19 {
20  explicit UseLock() = default;
21 };
22 
23 struct SkipLock
24 {
25  explicit SkipLock() = default;
26 };
27 
28 template <typename Mutex, typename Locking = UseLock, bool UseLocking = std::is_same_v<Locking, UseLock>>
29 struct LockGuard;
30 
31 
32 template <typename Mutex, typename Locking>
33 class LockGuard<Mutex, Locking, true> : public std::lock_guard<Mutex>
34 {
35 public:
36  using std::lock_guard<Mutex>::lock_guard;
37 };
38 
39 template <typename Mutex, typename Locking>
40 class LockGuard<Mutex, Locking, false>
41 {
42 public:
43  using mutex_type = Mutex;
44 
45  explicit LockGuard(Mutex& mtx)
46  {
47  }
48 
49  LockGuard(Mutex& mtx, std::adopt_lock_t)
50  {
51  }
52 
53  ~LockGuard() noexcept
54  {
55  }
56 
57  LockGuard(const LockGuard&) = delete;
58  LockGuard& operator=(const LockGuard&) = delete;
59 };
60 
61 END_NAMESPACE_MEMORY
Abstract class bringing basic locking features on synchronization and threading related classes...
Definition: locking.h:22
Definition: lock_guard.h:23
Definition: lock_guard.h:29
Definition: lock_guard.h:18