template<class T>
class ripple::packed_spinlock< T >
Classes to handle arrays of spinlocks packed into a single atomic integer:
Packed spinlocks allow for tremendously space-efficient lock-sharding but they come at a cost.
First, the implementation is necessarily low-level and uses advanced features like memory ordering and highly platform-specific tricks to maximize performance. This imposes a significant and ongoing cost to developers.
Second, and perhaps most important, is that the packing of multiple locks into a single integer which, albeit space-efficient, also has performance implications stemming from data dependencies, increased cache-coherency traffic between processors and heavier loads on the processor's load/store units.
To be sure, these locks can have advantages but they are definitely not general purpose locks and should not be thought of or used that way. The use cases for them are likely few and far between; without a compelling reason to use them, backed by profiling data, it might be best to use one of the standard locking primitives instead. Note that in most common platforms, std::mutex
is so heavily optimized that it can, usually, outperform spinlocks.
- Template Parameters
-
T | An unsigned integral type (e.g. std::uint16_t) A class that grabs a single packed spinlock from an atomic integer. |
This class meets the requirements of Lockable: https://en.cppreference.com/w/cpp/named_req/Lockable
Definition at line 89 of file spinlock.h.