Phosphor
|
#include <chunk_lock.h>
Public Member Functions | |
ChunkLock ()=default | |
ChunkLock (non_trivial_constructor_t t) | |
ChunkLock (const ChunkLock &other) | |
ChunkLock & | operator= (const ChunkLock &other) |
void | lockSlave () |
bool | tryLockSlave () |
void | unlockSlave () |
SlaveChunkLock & | slave () |
void | lockMaster () |
void | unlockMaster () |
MasterChunkLock & | master () |
Protected Types | |
enum | State { Unlocked = 0x00, SlaveLocked, MasterLocked } |
Protected Attributes | |
std::atomic< State > | state |
char | cacheline_pad [64-sizeof(std::atomic< State >)] |
ChunkLock is used to encapsulate the logic behind locking of a TraceLog::ChunkTenant. It is used to safely handle transitions between various states that a ChunkTenant might be in.
ChunkLock is conceptually the merging of two spin-locks, there are 3 states:
There are 4 transitions between states:
This is somewhat similar to a Reader/Writer lock with only one reader
|
default |
phosphor::ChunkLock::ChunkLock | ( | non_trivial_constructor_t | t | ) |
Non-trivial constructor for regular use
void phosphor::ChunkLock::lockMaster | ( | ) |
This method will acquire the master lock
void phosphor::ChunkLock::lockSlave | ( | ) |
This method will acquire the slave lock.
This specific method typically shouldn't be used and instead slaveMaybeLock() should be used as the end-user usually won't want to block while the master lock is held. This method is included to allow for a complete Lockable
concept over the slave lock.
MasterChunkLock & phosphor::ChunkLock::master | ( | ) |
SlaveChunkLock & phosphor::ChunkLock::slave | ( | ) |
bool phosphor::ChunkLock::tryLockSlave | ( | ) |
This method will attempt to acquire the slave lock without blocking if the master lock is currently held.
void phosphor::ChunkLock::unlockMaster | ( | ) |
This method will release the master lock
When not built as debug this will behave identically to unlockSlave() as it will not verify the starting state for performance reasons.
void phosphor::ChunkLock::unlockSlave | ( | ) |
This method will release the slave lock
When not built as debug this will behave identically to unlockMaster() as it will not verify the starting state for performance reasons.