Pull from FB rev 63ce89e2f2301e6bba44a111cc7d4218022156f6
[folly.git] / folly / docs / SmallLocks.md
1 `folly/SmallLocks.h`
2 --------------------
3
4 This module is currently x64 only.
5
6 This header defines two very small mutex types.  These are useful in
7 highly memory-constrained environments where contention is unlikely.
8 The purpose of these is to allow fine-grained locking in massive data
9 structures where memory is at a premium.  Often, each record may have
10 a spare bit or byte lying around, so sometimes these can be tacked on
11 with no additional memory cost.
12
13 There are two types exported from this header.  `MicroSpinLock` is a
14 single byte lock, and `PicoSpinLock` can be wrapped around an
15 integer to use a single bit as a lock.  Why do we have both?
16 Because you can't use x64 `bts` on a single byte, so
17 `sizeof(MicroSpinLock)` is smaller than `sizeof(PicoSpinLock)` can
18 be, giving it some use cases.
19
20 Both the locks in this header model the C++11 Lockable concept.  So
21 you can use `std::lock_guard` or `std::unique_lock` to lock them in an
22 RAII way if you want.
23
24 Additional information is in the header.