FOLLY: SmallLocks.h














































FOLLY: SmallLocks.h



This module is currently x64 only.
This header defines two very small types of mutexes. These are useful in very memory constrained environments where contention is unlikely. The purpose of these is to enable fine-grained locking in massive data structures where memory is at a premium. Each entry can often have a spare bit or byte, so sometimes they can be concatenated without additional memory overhead.
Two types are exported from this header. MicroSpinLock is a single-byte lock, and PicoSpinLock can be wrapped with an integer and use a single bit as a lock. Why do we have both? Because you can't use x64 bts per byte, so sizeof(MicroSpinLock) is smaller than sizeof(PicoSpinLock) can be, which gives it some use cases.
Both locks in this header model the C++11 Lockable concept. So you can use std::lock_guard or std::unique_lock to lock them in a RAII way if you want.

Comments