#include <sync.hh>
Classes | |
class | Lock |
struct | ReadLock |
struct | WriteLock |
Public Member Functions | |
SyncBase (const T &data) | |
SyncBase (T &&data) noexcept | |
WriteLock | lock () |
ReadLock | readLock () const |
This template class ensures synchronized access to a value of type T. It is used as follows:
struct Data { int x; ... };
Sync<Data> data;
{ auto data_(data.lock()); data_->x = 123; }
Here, "data" is automatically unlocked when "data_" goes out of scope.
|
inline |
Acquire write (exclusive) access to the inner value.
|
inline |
Acquire read access to the inner value. When using std::shared_mutex
, this will use a shared lock.