CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::TAsyncSharedMutex< ExecutorType > Class Template Reference

#include <CeresEngine/Foundation/Threading/AsyncMutex.hpp>

Classes

class  Lock
 A scoped RAII lock holder for a AsyncSharedMutex. More...
 
class  LockOperation
 

Public Member Functions

 TAsyncSharedMutex ()
 Creates a new async shared mutex.
 
 TAsyncSharedMutex (ExecutorType &&executor)
 
 ~TAsyncSharedMutex ()=default
 
 TAsyncSharedMutex (const TAsyncSharedMutex &)=delete
 
 TAsyncSharedMutex (TAsyncSharedMutex &&)=delete
 
TAsyncSharedMutexoperator= (const TAsyncSharedMutex &)=delete
 
TAsyncSharedMutexoperator= (TAsyncSharedMutex &&)=delete
 
LockOperation lock_shared ()
 Locks the mutex in a shared state.
 
LockOperation lock ()
 Locks the mutex in an exclusive state.
 
auto try_lock_shared () -> bool
 
bool try_lock ()
 
void unlock_shared ()
 Unlocks a single shared state user.
 
void unlock ()
 Unlocks the mutex from its exclusive state.
 

Private Types

enum class  State { Unlocked , LockedShared , LockedExclusive }
 

Private Member Functions

bool try_lock_shared_locked (UniqueLock< Mutex > &lk)
 
bool try_lock_locked (UniqueLock< Mutex > &lk)
 
void wakeWaiters (UniqueLock< Mutex > &lk)
 

Private Attributes

ExecutorType mExecutor
 This executor is for resuming multiple shared waiters.
 
Mutex mMutex
 
State mState = State::Unlocked
 
uint64_t mSharedUsers = 0
 The current number of shared users that have acquired the lock.
 
uint64_t mExclusiveWaiters = 0
 The current number of exclusive waiters waiting to acquire the lock.
 
LockOperationmHeadWaiter = nullptr
 
LockOperationmTailWaiter = nullptr
 

Friends

class LockOperation
 

Member Enumeration Documentation

◆ State

template<typename ExecutorType = InlineExecutor>
enum class CeresEngine::TAsyncSharedMutex::State
strongprivate
Enumerator
Unlocked 
LockedShared 
LockedExclusive 

Constructor & Destructor Documentation

◆ TAsyncSharedMutex() [1/4]

template<typename ExecutorType = InlineExecutor>
CeresEngine::TAsyncSharedMutex< ExecutorType >::TAsyncSharedMutex ( )
inlineexplicit

Creates a new async shared mutex.

◆ TAsyncSharedMutex() [2/4]

template<typename ExecutorType = InlineExecutor>
CeresEngine::TAsyncSharedMutex< ExecutorType >::TAsyncSharedMutex ( ExecutorType &&  executor)
inlineexplicit
Parameters
executorThe executor for when multiple shared waiters can be woken up at the same time, each shared waiter will be scheduled to immediately run on this executor in parallel.

◆ ~TAsyncSharedMutex()

◆ TAsyncSharedMutex() [3/4]

template<typename ExecutorType = InlineExecutor>
CeresEngine::TAsyncSharedMutex< ExecutorType >::TAsyncSharedMutex ( const TAsyncSharedMutex< ExecutorType > &  )
delete

◆ TAsyncSharedMutex() [4/4]

template<typename ExecutorType = InlineExecutor>
CeresEngine::TAsyncSharedMutex< ExecutorType >::TAsyncSharedMutex ( TAsyncSharedMutex< ExecutorType > &&  )
delete

Member Function Documentation

◆ lock()

template<typename ExecutorType = InlineExecutor>
LockOperation CeresEngine::TAsyncSharedMutex< ExecutorType >::lock ( )
inline

Locks the mutex in an exclusive state.

◆ lock_shared()

template<typename ExecutorType = InlineExecutor>
LockOperation CeresEngine::TAsyncSharedMutex< ExecutorType >::lock_shared ( )
inline

Locks the mutex in a shared state.

If there are any exclusive waiters then the shared waiters will also wait so the exclusive waiters are not starved.

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ try_lock()

template<typename ExecutorType = InlineExecutor>
bool CeresEngine::TAsyncSharedMutex< ExecutorType >::try_lock ( )
inline
Returns
True if the lock could immediately be acquired in an exclusive state.

◆ try_lock_locked()

template<typename ExecutorType = InlineExecutor>
bool CeresEngine::TAsyncSharedMutex< ExecutorType >::try_lock_locked ( UniqueLock< Mutex > &  lk)
inlineprivate

◆ try_lock_shared()

template<typename ExecutorType = InlineExecutor>
auto CeresEngine::TAsyncSharedMutex< ExecutorType >::try_lock_shared ( ) -> bool
inline
Returns
True if the lock could immediately be acquired in a shared state.

◆ try_lock_shared_locked()

template<typename ExecutorType = InlineExecutor>
bool CeresEngine::TAsyncSharedMutex< ExecutorType >::try_lock_shared_locked ( UniqueLock< Mutex > &  lk)
inlineprivate

◆ unlock()

template<typename ExecutorType = InlineExecutor>
void CeresEngine::TAsyncSharedMutex< ExecutorType >::unlock ( )
inline

Unlocks the mutex from its exclusive state.

If there is a following exclusive waiter then that exclusive waiter acquires the lock. If there are 1 or more shared waiters then all the shared waiters acquire the lock in a shared state in parallel and are resumed on the original thread pool this shared mutex was created with.

◆ unlock_shared()

template<typename ExecutorType = InlineExecutor>
void CeresEngine::TAsyncSharedMutex< ExecutorType >::unlock_shared ( )
inline

Unlocks a single shared state user.

REQUIRES that the lock was first acquired exactly once via lock_shared() or try_lock_shared() before being called, otherwise undefined behavior.

If the shared user count drops to zero and this lock has an exclusive waiter then the exclusive waiter acquires the lock.

◆ wakeWaiters()

template<typename ExecutorType = InlineExecutor>
void CeresEngine::TAsyncSharedMutex< ExecutorType >::wakeWaiters ( UniqueLock< Mutex > &  lk)
inlineprivate

Friends And Related Symbol Documentation

◆ LockOperation

template<typename ExecutorType = InlineExecutor>
friend class LockOperation
friend

Member Data Documentation

◆ mExclusiveWaiters

template<typename ExecutorType = InlineExecutor>
uint64_t CeresEngine::TAsyncSharedMutex< ExecutorType >::mExclusiveWaiters = 0
private

The current number of exclusive waiters waiting to acquire the lock.

This is used to block new incoming shared lock attempts so the exclusive waiter is not starved.

◆ mExecutor

template<typename ExecutorType = InlineExecutor>
ExecutorType CeresEngine::TAsyncSharedMutex< ExecutorType >::mExecutor
private

This executor is for resuming multiple shared waiters.

◆ mHeadWaiter

template<typename ExecutorType = InlineExecutor>
LockOperation* CeresEngine::TAsyncSharedMutex< ExecutorType >::mHeadWaiter = nullptr
private

◆ mMutex

template<typename ExecutorType = InlineExecutor>
Mutex CeresEngine::TAsyncSharedMutex< ExecutorType >::mMutex
private

◆ mSharedUsers

template<typename ExecutorType = InlineExecutor>
uint64_t CeresEngine::TAsyncSharedMutex< ExecutorType >::mSharedUsers = 0
private

The current number of shared users that have acquired the lock.

◆ mState

template<typename ExecutorType = InlineExecutor>
State CeresEngine::TAsyncSharedMutex< ExecutorType >::mState = State::Unlocked
private

◆ mTailWaiter

template<typename ExecutorType = InlineExecutor>
LockOperation* CeresEngine::TAsyncSharedMutex< ExecutorType >::mTailWaiter = nullptr
private

The documentation for this class was generated from the following file: