template<typename Data, typename Mutex = engine::Mutex>
class concurrent::Variable< Data, Mutex >
Container for shared data protected with a mutex of any type (mutex, shared mutex, etc.).
Example usage:
constexpr auto kTestString = "Test string";
struct Data {
int x = 0;
std::string s{};
};
{
auto data_ptr = data.Lock();
data_ptr->s = kTestString;
}
{
auto data_ptr = data.SharedLock();
ASSERT_EQ(data_ptr->s, kTestString);
}
- See also
- Synchronization Primitives
Definition at line 58 of file variable.hpp.
|
template<typename... Arg> |
| Variable (Arg &&... arg) |
|
LockedPtr< std::unique_lock< Mutex >, Data > | UniqueLock () |
|
LockedPtr< std::unique_lock< Mutex >, const Data > | UniqueLock () const |
|
std::optional< LockedPtr< std::unique_lock< Mutex >, const Data > > | UniqueLock (std::try_to_lock_t) const |
|
std::optional< LockedPtr< std::unique_lock< Mutex >, Data > > | UniqueLock (std::try_to_lock_t) |
|
std::optional< LockedPtr< std::unique_lock< Mutex >, const Data > > | UniqueLock (std::chrono::milliseconds try_duration) const |
|
std::optional< LockedPtr< std::unique_lock< Mutex >, Data > > | UniqueLock (std::chrono::milliseconds try_duration) |
|
LockedPtr< std::shared_lock< Mutex >, const Data > | SharedLock () const |
|
LockedPtr< std::shared_lock< Mutex >, Data > | SharedMutableLockUnsafe () |
|
LockedPtr< std::lock_guard< Mutex >, Data > | Lock () |
|
LockedPtr< std::lock_guard< Mutex >, const Data > | Lock () const |
|
Mutex & | GetMutexUnsafe () const |
|
Data & | GetDataUnsafe () |
|
const Data & | GetDataUnsafe () const |
|
template<typename Data , typename Mutex = engine::Mutex>
Get raw data. Use with extreme caution, only for cases where it is impossible to access data with safe methods (e.g. std::scoped_lock with multiple mutexes). For simple use cases call Lock(), UniqueLock(), SharedLock() instead.
Definition at line 102 of file variable.hpp.