![]() |
ImFusion C++ SDK 4.5.0
|
#include <ImFusion/Core/Threading/Protected.h>
RAII lock guard that provides exclusive access to a synchronized resource. More...
RAII lock guard that provides exclusive access to a synchronized resource.
This class combines a lock acquisition with access to the protected resource. The lock is acquired on construction and automatically released on destruction, following the RAII (Resource Acquisition Is Initialization) pattern.
Locked objects provide pointer-like semantics via operator* and operator-> to access the underlying resource while the lock is held.
| U | The type of the resource being protected |
Usage example:
Public Types | |
| using | value_type = std::conditional_t<isConst, const T, T> |
| using | return_reference = std::conditional_t<isConst, const value_type&, value_type&> |
| using | return_ptr = std::conditional_t<isConst, const value_type*, value_type*> |
Public Member Functions | |
| Locked (std::shared_ptr< value_type > value, std::shared_ptr< std::mutex > sharedMutex) | |
| Constructs a Locked instance and acquires the mutex. | |
| Locked (std::shared_ptr< value_type > resource, std::shared_ptr< std::mutex > sharedMutex, std::adopt_lock_t) | |
| Constructs a Locked instance adopting an already-held lock. | |
| Locked (std::tuple< std::shared_ptr< value_type >, std::shared_ptr< std::mutex >, std::adopt_lock_t > t) | |
| Constructs a Locked instance adopting an already-held lock. | |
| Locked (Locked &&other)=delete | |
| return_reference | operator* () |
| Provides mutable reference access to the locked resource. | |
| return_ptr | operator-> () |
| Provides mutable pointer access to the locked resource. | |
| const value_type & | operator* () const |
| Provides const reference access to the locked resource. | |
| const value_type * | operator-> () const |
| Provides const pointer access to the locked resource. | |
Additional Inherited Members | |
| Protected Member Functions inherited from ImFusion::Utils::NotCopyable | |
| NotCopyable (NotCopyable &&) noexcept=default | |
| NotCopyable & | operator= (NotCopyable &&) noexcept=default |
| NotCopyable (const NotCopyable &)=delete | |
| NotCopyable & | operator= (const NotCopyable &)=delete |
|
inline |
Constructs a Locked instance and acquires the mutex.
| value | Shared pointer to the resource to protect. Must not be null. |
| sharedMutex | Shared pointer to the mutex protecting the resource. Must not be null. |
|
inline |
Constructs a Locked instance adopting an already-held lock.
| resource | Shared pointer to the resource to protect. Must not be null. |
| sharedMutex | Shared pointer to the mutex protecting the resource. Must not be null. The mutex must already be locked by the calling thread. |
|
inline |