2
3
4
5
6
7
8
9
10
11
12
13
14
15
17#ifndef MIR_SYNCHRONISED_H_
18#define MIR_SYNCHRONISED_H_
26
27
28
29
30
31
32
39 : value{std::move(initial_value)}
47
48
49
50
51
52
53
60 lock{std::move(from.lock)}
78
79
80
81
82
90
91
92
93
94 template<
typename Cv,
typename Predicate>
95 void wait(Cv& cv, Predicate stop_waiting)
97 cv.wait(lock, stop_waiting);
102 LockedImpl(std::unique_lock<std::mutex>&& lock, U& value)
104 lock{std::move(lock)}
109 std::unique_lock<std::mutex> lock;
113
114
115
116
117
118
119
122
123
124
125
126
127
130 return LockedImpl<T>{std::unique_lock{mutex}, value};
134
135
136
137
138
139
140
141
142
145
146
147
148
149
150
151 auto lock()
const -> LockedView
153 return LockedImpl<T
const>{std::unique_lock{mutex}, value};
156 std::mutex
mutable mutex;
Smart-pointer-esque accessor for the protected data.
Definition: synchronised.h:56
void wait(Cv &cv, Predicate stop_waiting)
Allows waiting for a condition variable.
Definition: synchronised.h:95
LockedImpl(LockedImpl &&from) noexcept
Definition: synchronised.h:58
void drop()
Relinquish access to the data.
Definition: synchronised.h:83
auto operator->() const -> U *
Definition: synchronised.h:72
auto operator*() const -> U &
Definition: synchronised.h:67
An object that enforces unique access to the data it contains.
Definition: synchronised.h:35
auto lock() const -> LockedView
Lock the data and return an accessor.
Definition: synchronised.h:151
Synchronised(T &&initial_value)
Definition: synchronised.h:38
Synchronised & operator=(Synchronised const &)=delete
auto lock() -> Locked
Lock the data and return an accessor.
Definition: synchronised.h:128
Synchronised(Synchronised const &)=delete