Commit eb4ef90 1 parent ce2e68e commit eb4ef90 Copy full SHA for eb4ef90
File tree 2 files changed +14
-4
lines changed
include/dice/template-library
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 8
8
9
9
namespace dice ::template_library {
10
10
11
+ template <typename T, typename Mutex = std::mutex>
12
+ struct mutex ;
13
+
11
14
/* *
12
15
* An RAII guard for a value behind a mutex.
13
16
* When this mutex_guard is dropped the lock is automatically released.
@@ -25,15 +28,17 @@ namespace dice::template_library {
25
28
using mutex_type = Mutex;
26
29
27
30
private:
31
+ friend struct mutex <T, Mutex>;
32
+
28
33
value_type *value_ptr_;
29
34
std::unique_lock<mutex_type> lock_;
30
35
31
- public:
32
36
mutex_guard (std::unique_lock<mutex_type> &&lock, T &value) noexcept
33
37
: value_ptr_{&value},
34
38
lock_{std::move (lock)} {
35
39
}
36
40
41
+ public:
37
42
mutex_guard () = delete ;
38
43
mutex_guard (mutex_guard const &other) noexcept = delete ;
39
44
mutex_guard &operator =(mutex_guard const &other) noexcept = delete ;
@@ -65,7 +70,7 @@ namespace dice::template_library {
65
70
* @tparam T value type stored
66
71
* @tparam Mutex the mutex type
67
72
*/
68
- template <typename T, typename Mutex = std::mutex >
73
+ template <typename T, typename Mutex>
69
74
struct mutex {
70
75
using value_type = T;
71
76
using mutex_type = Mutex;
Original file line number Diff line number Diff line change 9
9
10
10
namespace dice ::template_library {
11
11
12
+ template <typename T, typename Mutex = std::shared_mutex>
13
+ struct shared_mutex ;
14
+
12
15
/* *
13
16
* An RAII guard for a value behind a shared_mutex.
14
17
* When this shared_mutex_guard is dropped the lock is automatically released.
@@ -27,15 +30,17 @@ namespace dice::template_library {
27
30
using lock_type = std::conditional_t <std::is_const_v<T>, std::shared_lock<mutex_type>, std::unique_lock<mutex_type>>;
28
31
29
32
private:
33
+ friend struct shared_mutex <std::remove_const_t <T>, Mutex>;
34
+
30
35
value_type *value_ptr_;
31
36
lock_type lock_;
32
37
33
- public:
34
38
shared_mutex_guard (lock_type &&lock, T &value) noexcept
35
39
: value_ptr_{&value},
36
40
lock_{std::move (lock)} {
37
41
}
38
42
43
+ public:
39
44
shared_mutex_guard () = delete ;
40
45
shared_mutex_guard (shared_mutex_guard const &other) noexcept = delete ;
41
46
shared_mutex_guard &operator =(shared_mutex_guard const &other) noexcept = delete ;
@@ -67,7 +72,7 @@ namespace dice::template_library {
67
72
* @tparam T value type stored
68
73
* @tparam Mutex the mutex type
69
74
*/
70
- template <typename T, typename Mutex = std::shared_mutex >
75
+ template <typename T, typename Mutex>
71
76
struct shared_mutex {
72
77
using value_type = T;
73
78
using mutex_type = Mutex;
You can’t perform that action at this time.
0 commit comments