MySQL 8.0.39
Source Code Documentation
|
Lock-free pool of POOL_SIZE Block elements. More...
#include <shared_block_pool.h>
Classes | |
struct | L1_dcache_aligned_block |
In the event of inability to express ourselves with something like std::array<alignas<N> Block> we have to fallback to this method. More... | |
Public Member Functions | |
Block * | try_acquire (size_t thd_id) |
Given the THD identifier, try to acquire an instance of Block. More... | |
bool | try_release (size_t thd_id) |
Given the THD identifier, try to release an acquired instance of a Block. More... | |
Private Types | |
using | Shared_block_slot = Lock_free_pool< unsigned long long, POOL_SIZE, Alignment::L1_DCACHE_SIZE > |
Check whether all compile-time pre-conditions are set. More... | |
using | Shared_block_slot_element_type = typename Shared_block_slot::Type |
Be pedantic about the element type we used when building the slot type. More... | |
Private Attributes | |
std::array< L1_dcache_aligned_block, POOL_SIZE > | m_shared_block |
An array of L1-dcache aligned Blocks Note: This is not the same as: alignas(L1_DCACHE_SIZE) std::array<Block, POOL_SIZE> More... | |
Shared_block_slot | m_slot {FREE_SLOT} |
Lock-free slots. More... | |
Static Private Attributes | |
static constexpr Shared_block_slot_element_type | FREE_SLOT |
Constexpr variable denoting a non-occupied (free) slot. More... | |
static constexpr size_t | MODULO_MASK = POOL_SIZE - 1 |
Bitmask which enables us to implement modulo-arithmetic operation in single bitwise instruction. More... | |
Lock-free pool of POOL_SIZE Block elements.
Each Block element in a pool is represented by a slot. Each slot can be either free (default) or occupied. Acquiring the Block is possible only from an empty slot. Releasing the Block makes the slot free again.
Acquiring and releasing the Block is done via THD identifier on which, implicitly, modulo-arithmethic is applied in order to pick the right slot. To avoid questionable performance of modulo-arithmetic in its more general form, POOL_SIZE is constrained only to numbers which are power of two. This enables us to implement a modulo operation in single bitwise instruction. Check whether POOL_SIZE is a number which is power of two is run during the compile-time.
Given that this pool is envisioned to be used concurrently by multiple threads, both the slot and Block are aligned to the size of CPU L1 data-cache. This makes sure that we negate the effect of false-sharing (threads bouncing each ones data from cache).
|
private |
Check whether all compile-time pre-conditions are set.
Build a slot type: a lock-free pool of L1-DCACHE aligned unsigned long long's
|
private |
Be pedantic about the element type we used when building the slot type.
|
inline |
Given the THD identifier, try to acquire an instance of Block.
In the event of success, non-nullptr instance of Block will be returned and underlying slot will be marked as occupied. Otherwise, slot must have been already occupied in which case a nullptr will be returned.
Using the same THD identifier to re-acquire the Block (from the same slot) is supported but not possible if some other THD identifier is used.
[in] thd_id THD identifier.
|
inline |
Given the THD identifier, try to release an acquired instance of a Block.
In the event of success, slot will be marked as non-occupied. Assuming that Block is not empty, it will also be destroyed.
Trying to release the Block/slot by using some other THD identifier is not possible and will therefore render this operation as failed.
[in] thd_id THD identifier.
|
staticconstexprprivate |
Constexpr variable denoting a non-occupied (free) slot.
|
private |
An array of L1-dcache aligned Blocks Note: This is not the same as: alignas(L1_DCACHE_SIZE) std::array<Block, POOL_SIZE>
|
private |
Lock-free slots.
|
staticconstexprprivate |
Bitmask which enables us to implement modulo-arithmetic operation in single bitwise instruction.