|
CeresEngine 0.2.0
A game development framework
|
A mutex that can be locked asynchronously using 'co_await'. More...
#include <CeresEngine/Foundation/Threading/AsyncMutex.hpp>
Classes | |
| class | Lock |
| An object that holds onto a mutex lock for its lifetime and ensures that the mutex is unlocked when it is destructed. More... | |
| class | LockOperation |
| class | ScopedLockOperation |
Public Member Functions | |
| TAsyncMutex () noexcept=default | |
| Construct to a mutex that is not currently locked. | |
| TAsyncMutex (ExecutorType &&executor) noexcept | |
| ~TAsyncMutex () noexcept | |
| Destroys the mutex. | |
| bool | tryLock () noexcept |
| Attempt to acquire a lock on the mutex without blocking. | |
| bool | try_lock () noexcept |
| Attempt to acquire a lock on the mutex without blocking. | |
| LockOperation | lock () noexcept |
| Acquire a lock on the mutex asynchronously. | |
| ScopedLockOperation | scopedLock () noexcept |
| Acquire a lock on the mutex asynchronously, returning an object that will call unlock() automatically when it goes out of scope. | |
| void | unlock () |
| Unlock the mutex. | |
Private Attributes | |
| ExecutorType | mExecutor |
| This executor is for resuming multiple shared waiters. | |
| Atomic< std::uintptr_t > | mState = kNotLocked |
| This field provides synchronisation for the mutex. | |
| LockOperation * | mWaiters = nullptr |
| Linked list of async lock operations that are waiting to acquire the mutex. | |
Static Private Attributes | |
| static constexpr std::uintptr_t | kNotLocked = 1 |
| static constexpr std::uintptr_t | kLockedNoWaiters = 0 |
Friends | |
| class | LockOperation |
A mutex that can be locked asynchronously using 'co_await'.
Ownership of the mutex is not tied to any particular thread. This allows the coroutine owning the lock to transition from one thread to another while holding a lock.
Implementation is lock-free, using only std::atomic values for synchronisation. Awaiting coroutines are suspended without blocking the current thread if the lock could not be acquired synchronously.
|
defaultnoexcept |
Construct to a mutex that is not currently locked.
|
inlineexplicitnoexcept |
| executor | The executor for when multiple waiters can be woken up at the same time, each shared waiter will be scheduled to immediately run on this executor in parallel. |
|
inlinenoexcept |
Destroys the mutex.
Behaviour is undefined if there are any outstanding coroutines still waiting to acquire the lock.
|
inlinenoexcept |
Acquire a lock on the mutex asynchronously.
If the lock could not be acquired synchronously then the awaiting coroutine will be suspended and later resumed when the lock becomes available. If suspended, the coroutine will be resumed inside the call to unlock() from the previous lock owner.
|
inlinenoexcept |
Acquire a lock on the mutex asynchronously, returning an object that will call unlock() automatically when it goes out of scope.
If the lock could not be acquired synchronously then the awaiting coroutine will be suspended and later resumed when the lock becomes available. If suspended, the coroutine will be resumed inside the call to unlock() from the previous lock owner.
|
inlinenoexcept |
Attempt to acquire a lock on the mutex without blocking.
|
inlinenoexcept |
Attempt to acquire a lock on the mutex without blocking.
|
inline |
Unlock the mutex.
Must only be called by the current lock-holder.
If there are lock operations waiting to acquire the mutex then the next lock operation in the queue will be resumed inside this call.
|
friend |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
This executor is for resuming multiple shared waiters.
|
private |
This field provides synchronisation for the mutex.
It can have three kinds of values:
|
private |
Linked list of async lock operations that are waiting to acquire the mutex.
These operations will acquire the lock in the order they appear in this list.