CatapultServer  v0.5.0.1 (Elephant)
catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy > Class Template Reference
Inheritance diagram for catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >:
Collaboration diagram for catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >:

Classes

class  LockGuard
 Base class for RAII lock guards. More...
 
struct  ReaderLockGuard
 A reader lock guard. More...
 
struct  WriterLockGuard
 A writer lock guard. More...
 

Public Member Functions

 BasicSpinReaderWriterLock ()
 Creates an unlocked lock. More...
 
ReaderLockGuard acquireReader ()
 Blocks until a reader lock can be acquired. More...
 
bool isWriterPending () const
 Returns true if there is a pending (or active) writer. More...
 
bool isWriterActive () const
 Returns true if there is an active writer. More...
 
bool isReaderActive () const
 Returns true if there is an active reader. More...
 

Private Member Functions

bool isSet (uint16_t mask) const
 

Static Private Member Functions

static void Yield ()
 

Private Attributes

std::atomic< uint16_t > m_value
 

Static Private Attributes

static constexpr uint16_t Active_Writer_Flag = 0x8000
 
static constexpr uint16_t Pending_Writer_Mask = 0x7F00
 
static constexpr uint16_t Reader_Mask = 0x00FF
 
static constexpr uint16_t Writer_Mask = Pending_Writer_Mask | Active_Writer_Flag
 
static constexpr uint16_t Active_Reader_Increment = 0x0001
 
static constexpr uint16_t Pending_Writer_Increment = 0x0100
 

Detailed Description

template<typename TReaderNotificationPolicy>
class catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >

Custom reader writer lock implemented by using an atomic that allows multiple readers and a single writer and prefers writers.

Note
  • 128 max writers
  • 256 max readers
  • writer lock must be acquired via a reader lock promotion

Constructor & Destructor Documentation

◆ BasicSpinReaderWriterLock()

template<typename TReaderNotificationPolicy >
catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::BasicSpinReaderWriterLock ( )
inline

Creates an unlocked lock.

Member Function Documentation

◆ acquireReader()

template<typename TReaderNotificationPolicy >
ReaderLockGuard catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::acquireReader ( )
inline

Blocks until a reader lock can be acquired.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isReaderActive()

template<typename TReaderNotificationPolicy >
bool catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::isReaderActive ( ) const
inline

Returns true if there is an active reader.

Here is the call graph for this function:

◆ isSet()

template<typename TReaderNotificationPolicy >
bool catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::isSet ( uint16_t  mask) const
inlineprivate
Here is the caller graph for this function:

◆ isWriterActive()

template<typename TReaderNotificationPolicy >
bool catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::isWriterActive ( ) const
inline

Returns true if there is an active writer.

Here is the call graph for this function:

◆ isWriterPending()

template<typename TReaderNotificationPolicy >
bool catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::isWriterPending ( ) const
inline

Returns true if there is a pending (or active) writer.

Here is the call graph for this function:

◆ Yield()

template<typename TReaderNotificationPolicy >
static void catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Yield ( )
inlinestaticprivate
Here is the caller graph for this function:

Member Data Documentation

◆ Active_Reader_Increment

template<typename TReaderNotificationPolicy >
constexpr uint16_t catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Active_Reader_Increment = 0x0001
staticconstexprprivate

◆ Active_Writer_Flag

template<typename TReaderNotificationPolicy >
constexpr uint16_t catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Active_Writer_Flag = 0x8000
staticconstexprprivate

◆ m_value

template<typename TReaderNotificationPolicy >
std::atomic<uint16_t> catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::m_value
private

◆ Pending_Writer_Increment

template<typename TReaderNotificationPolicy >
constexpr uint16_t catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Pending_Writer_Increment = 0x0100
staticconstexprprivate

◆ Pending_Writer_Mask

template<typename TReaderNotificationPolicy >
constexpr uint16_t catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Pending_Writer_Mask = 0x7F00
staticconstexprprivate

◆ Reader_Mask

template<typename TReaderNotificationPolicy >
constexpr uint16_t catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Reader_Mask = 0x00FF
staticconstexprprivate

◆ Writer_Mask

template<typename TReaderNotificationPolicy >
constexpr uint16_t catapult::utils::BasicSpinReaderWriterLock< TReaderNotificationPolicy >::Writer_Mask = Pending_Writer_Mask | Active_Writer_Flag
staticconstexprprivate

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