![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include <sync.hh>
Classes | |
| class | Lock |
| struct | WriteLock |
| struct | ReadLock |
Public Types | |
| using | element_type = T |
Public Member Functions | |
| SyncBase (const T &data) | |
| SyncBase (T &&data) noexcept | |
|
template<typename... Ts> requires requires { T{std::forward<Ts>(args)...}; } | |
| SyncBase (Ts &&... args) | |
| SyncBase (SyncBase &&other) 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.