Phosphor
phosphor::ChunkLock Class Reference

#include <chunk_lock.h>

Inheritance diagram for phosphor::ChunkLock:
phosphor::MasterChunkLock phosphor::SlaveChunkLock

Public Member Functions

 ChunkLock ()=default
 
 ChunkLock (non_trivial_constructor_t t)
 
 ChunkLock (const ChunkLock &other)
 
ChunkLockoperator= (const ChunkLock &other)
 
void lockSlave ()
 
bool tryLockSlave ()
 
void unlockSlave ()
 
SlaveChunkLockslave ()
 
void lockMaster ()
 
void unlockMaster ()
 
MasterChunkLockmaster ()
 

Protected Types

enum  State { Unlocked = 0x00, SlaveLocked, MasterLocked }
 

Protected Attributes

std::atomic< State > state
 
char cacheline_pad [64-sizeof(std::atomic< State >)]
 

Detailed Description

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:

  • slaveLock [Unlocked->SlaveLocked]
  • slaveUnlock [SlaveLocked->Unlocked]
  • masterLock [Unlocked->MasterLocked]
  • masterUnlock [MasterLocked->Unlocked]

This is somewhat similar to a Reader/Writer lock with only one reader

Constructor & Destructor Documentation

phosphor::ChunkLock::ChunkLock ( )
default

ChunkLock is trivially constructible to allow for use in MacOS compatible thread_local variables.

ChunkLock is 'constructed' by memsetting to zero

phosphor::ChunkLock::ChunkLock ( non_trivial_constructor_t  t)

Non-trivial constructor for regular use

Member Function Documentation

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 ( )
Returns
A MasterChunkLock reference to this object's master lock
SlaveChunkLock & phosphor::ChunkLock::slave ( )
Returns
A SlaveChunkLock reference to this object's slave lock
bool phosphor::ChunkLock::tryLockSlave ( )

This method will attempt to acquire the slave lock without blocking if the master lock is currently held.

Returns
true if slave lock is acquired, false if the acquiring the slave lock would block waiting for the master lock
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.


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