Cpp Utilities 1.2.3
Classes | Public Member Functions | List of all members
Memory::RWSpinLock Class Reference

High-performance read-write-spinlock, see RWSpinLock.hpp for details. More...

#include <RWSpinLock.hpp>

Classes

class  ReadHolder
 RAII guard for read lock with RWSpinLock::lock_shared() on construction and RWSpinLock::unlock_shared() on destruction. More...
 
class  UpgradedHolder
 RAII guard for upgrade lock with RWSpinLock::lock_upgrade() on construction and RWSpinLock::unlock_upgrade() on destruction. More...
 
class  WriteHolder
 RAII guard for write lock with RWSpinLock::lock() on construction and RWSpinLock::unlock() on destruction. More...
 

Public Member Functions

constexpr RWSpinLock ()
 
 RWSpinLock (RWSpinLock const &)=delete
 
RWSpinLockoperator= (RWSpinLock const &)=delete
 
void lock ()
 Lockable Concept. More...
 
void unlock ()
 Writer is responsible for clearing up both the UPGRADED and WRITER bits. More...
 
void lock_shared ()
 SharedLockable Concept. More...
 
void unlock_shared ()
 
void unlock_and_lock_shared ()
 Downgrade the lock from writer status to reader status. More...
 
void lock_upgrade ()
 UpgradeLockable Concept. More...
 
void unlock_upgrade ()
 
void unlock_upgrade_and_lock ()
 unlock upgrade and try to acquire write lock More...
 
void unlock_upgrade_and_lock_shared ()
 unlock upgrade and read lock atomically More...
 
void unlock_and_lock_upgrade ()
 write unlock and upgrade lock atomically More...
 
bool try_lock ()
 
bool try_lock_shared ()
 Try to get reader permission on the lock. This can fail if we find out someone is a writer or upgrader. More...
 
bool try_unlock_upgrade_and_lock ()
 try to unlock upgrade and write lock atomically More...
 
bool try_lock_upgrade ()
 try to acquire an upgradable lock. More...
 
int32_t bits () const
 mainly for debugging purposes. More...
 

Detailed Description

High-performance read-write-spinlock, see RWSpinLock.hpp for details.

Constructor & Destructor Documentation

◆ RWSpinLock() [1/2]

constexpr Memory::RWSpinLock::RWSpinLock ( )
inlineconstexpr

◆ RWSpinLock() [2/2]

Memory::RWSpinLock::RWSpinLock ( RWSpinLock const &  )
delete

Member Function Documentation

◆ operator=()

RWSpinLock & Memory::RWSpinLock::operator= ( RWSpinLock const &  )
delete

◆ lock()

void Memory::RWSpinLock::lock ( )
inline

Lockable Concept.

◆ unlock()

void Memory::RWSpinLock::unlock ( )
inline

Writer is responsible for clearing up both the UPGRADED and WRITER bits.

◆ lock_shared()

void Memory::RWSpinLock::lock_shared ( )
inline

SharedLockable Concept.

◆ unlock_shared()

void Memory::RWSpinLock::unlock_shared ( )
inline

◆ unlock_and_lock_shared()

void Memory::RWSpinLock::unlock_and_lock_shared ( )
inline

Downgrade the lock from writer status to reader status.

◆ lock_upgrade()

void Memory::RWSpinLock::lock_upgrade ( )
inline

UpgradeLockable Concept.

◆ unlock_upgrade()

void Memory::RWSpinLock::unlock_upgrade ( )
inline

◆ unlock_upgrade_and_lock()

void Memory::RWSpinLock::unlock_upgrade_and_lock ( )
inline

unlock upgrade and try to acquire write lock

◆ unlock_upgrade_and_lock_shared()

void Memory::RWSpinLock::unlock_upgrade_and_lock_shared ( )
inline

unlock upgrade and read lock atomically

◆ unlock_and_lock_upgrade()

void Memory::RWSpinLock::unlock_and_lock_upgrade ( )
inline

write unlock and upgrade lock atomically

◆ try_lock()

bool Memory::RWSpinLock::try_lock ( )
inline

Attempt to acquire writer permission. Return false if we didn't get it.

◆ try_lock_shared()

bool Memory::RWSpinLock::try_lock_shared ( )
inline

Try to get reader permission on the lock. This can fail if we find out someone is a writer or upgrader.

Setting the UPGRADED bit would allow a writer-to-be to indicate its intention to write and block any new readers while waiting for existing readers to finish and release their read locks. This helps avoid starving writers (promoted from upgraders).

◆ try_unlock_upgrade_and_lock()

bool Memory::RWSpinLock::try_unlock_upgrade_and_lock ( )
inline

try to unlock upgrade and write lock atomically

◆ try_lock_upgrade()

bool Memory::RWSpinLock::try_lock_upgrade ( )
inline

try to acquire an upgradable lock.

Note
when failed, we cannot flip the UPGRADED bit back, as in this case there is either another upgrade lock or a write lock. If it's a write lock, the bit will get cleared up when that lock's done with unlock().

◆ bits()

int32_t Memory::RWSpinLock::bits ( ) const
inline

mainly for debugging purposes.


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