#include <core/memory/guards.hpp>
template<typename T, typename Lock>
WriteGuard class
Provides safe read-write access to an object using a lock.
Template parameters | |
---|---|
T | Guarded object type. |
Lock | Held lock type. |
This class was created because there are multiple parts of the code that need to provide access to objects in a thread-safe manner.
Usage example
using AssetMetaWrite = core::memory::WriteGuard<AssetMeta, std::unique_lock<std::shared_mutex>>;
Constructors, destructors, conversion operators
- WriteGuard(T& object, Lock&& lock)
- Constructor.
- WriteGuard(WriteGuard&& other) noexcept
- Move constructs.
Public functions
- auto get() -> T&
- Gets a reference to the underlying object.
- auto operator*() -> T&
- Gets a reference to the underlying object.
- auto operator->() -> T*
- Gets a pointer to the underlying object.
- auto get() const -> const T&
- Gets a reference to the underlying object.
- auto operator*() const -> const T&
- Gets a reference to the underlying object.
- auto operator->() const -> const T*
- Gets a pointer to the underlying object.
Function documentation
template<typename T, typename Lock>
cubos:: core:: memory:: WriteGuard<T, Lock>:: WriteGuard(T& object,
Lock&& lock)
Constructor.
Parameters | |
---|---|
object | Object to guard. |
lock | Lock to hold. |
template<typename T, typename Lock>
cubos:: core:: memory:: WriteGuard<T, Lock>:: WriteGuard(WriteGuard&& other) noexcept
Move constructs.
Parameters | |
---|---|
other | Guard to move from. |
template<typename T, typename Lock>
T& cubos:: core:: memory:: WriteGuard<T, Lock>:: get()
Gets a reference to the underlying object.
Returns | Underlying object. |
---|
template<typename T, typename Lock>
T& cubos:: core:: memory:: WriteGuard<T, Lock>:: operator*()
Gets a reference to the underlying object.
Returns | Underlying object. |
---|
template<typename T, typename Lock>
T* cubos:: core:: memory:: WriteGuard<T, Lock>:: operator->()
Gets a pointer to the underlying object.
Returns | Underlying object. |
---|
template<typename T, typename Lock>
const T& cubos:: core:: memory:: WriteGuard<T, Lock>:: get() const
Gets a reference to the underlying object.
Returns | Underlying object. |
---|
template<typename T, typename Lock>
const T& cubos:: core:: memory:: WriteGuard<T, Lock>:: operator*() const
Gets a reference to the underlying object.
Returns | Underlying object. |
---|
template<typename T, typename Lock>
const T* cubos:: core:: memory:: WriteGuard<T, Lock>:: operator->() const
Gets a pointer to the underlying object.
Returns | Underlying object. |
---|