A tiny one‐byte spinlock with a configurable spin and yield budget.
Synopsis
Declared in <folly/MicroLock.h>
template<
unsigned int MaxSpins = 1000,
unsigned int MaxYields = 0>
class MicroLockBase
: public MicroLockCore
Base Classes
Name |
Description |
Base class holding the lock byte and the bit‐packing helpers shared by every MicroLock specialization. |
Types
Name |
Description |
A lock guard which allows reading and writing to the unused bits of the lock as data. |
Member Functions
Name |
Description |
Loads the data stored in the unused bits of the lock atomically. |
|
Acquire the lock, blocking until it is held. |
|
Locks the lock and returns the data stored in the unused bits of the lock. This is useful when you want to use the unused bits of the lock to store data, in which case reading and locking should be done in one atomic operation. |
|
Stores the data in the unused bits of the lock atomically. Since 2 bits are used by the lock, the most significant 2 bits of the provided value will be ignored. |
|
Try to acquire the lock without blocking. |
|
Release the lock without modifying the stored data bits. |
|
Unlocks the lock and stores the bits of the provided value into the data bits. Since 2 bits are used by the lock, the most significant 2 bits of the provided value will be ignored. |
Protected Member Functions
Name |
Description |
Mask for bit indicating that the flag is held. |
|
Acquire the lock along the contended path, spinning then yielding. |
|
Unlock the lock, applying a modifier to compute the stored word. |
|
Mask for bit indicating that there is a waiter that should be woken up. |
Protected Static Member Functions
Name |
Description |
Decodes the value stored in the unused bits of the lock. |
|
Decode the user data stored in the data bits of a lock word. |
|
Encodes the value for the unused bits of the lock. |
|
Encode user data into the data bits of a lock word, preserving lock bits. |
Protected Data Members
Name |
Description |
The single byte holding both the lock bits and the packed data bits. |
Protected Static Data Members
Name |
Description |
Mask selecting the bits available for user data. |
|
Mask selecting the bits reserved for lock state. |
|
Number of low bits reserved for lock state. |
Template Parameters
Name |
Description |
MaxSpins |
The maximum number of spins before yielding. |
MaxYields |
The maximum number of yields before parking. |
Created with MrDocs