22#include <boost/core/noncopyable.hpp>
23#include <boost/unordered/unordered_flat_map.hpp>
107 private boost::noncopyable
164 inline std::optional<void*>
get()
const;
333 if (map_it->second.m_tl_state_ptr == new_value)
359 constexpr size_t MAP_RESERVED_SIZE = 1024;
362 &&
"By contract: only call us if `reset_release() != INOPERATIVE` and only immediately after that.");
363 assert(new_value &&
"Null values not allowed; and reset_set() is not to be used for erasing.");
375 std::optional<void*> result;
381 : map_it->second.m_tl_state_ptr);
Internal-use helper for Thread_local_ptr which encapsulates that guy's thread_locally-accessed TLS pa...
Reset_result reset_release(void *new_value)
Phase 1.1 of Thread_local_ptr::reset(): Executes reset(new_value) up-to when one potentially calls cl...
const per_tlp_key_t m_per_tlp_key
*this's unique ID; see important notes on per_tlp_key_t.
std::optional< void * > get() const
Looks up and returns the value last placed via reset_release() + reset_set(), or null if those have n...
static thread_local Global_tl_state s_this_thread_state
See Global_tl_state doc header.
static thread_local bool s_this_thread_global_tl_state_operative
A thread-local flag that starts at true and becomes false to indicate do not access Global_tl_state.
Reset_result
Encodes result of reset_release(), indicating what the calling Thread_local_ptr::reset() should do ne...
@ S_DUPE
*this is operative; key was looked up (X = result, possibly null); X equals new_value; reset() should...
@ S_OK
*this is operative; key was looked up (X = result, possibly null); X does not equal new_value; X,...
@ S_INOPERATIVE
*this is inoperative permanently (we are near thread exit or exit()); do not touch *this further; res...
~Thread_local_ptr_cache()
Dtor.
Unique_id_holder::id_t per_tlp_key_t
64-bit (at worst) key for Tlp_states_map, uniquely generated by Unique_id_holder.
void release()
Our part of Thread_local_ptr::release().
Thread_local_ptr_cache()
Ctor. No apparent effect.
void reset_set(void *new_value)
Phase 3.2 of Thread_local_ptr::reset(): Executes reset(new_value) just-after the update of the canoni...
boost::unordered_flat_map< per_tlp_key_t, Per_tlp_state > Tlp_states_map
The map for a given thread, with a Per_tlp_state per Thread_local_ptr_cache (<=> Thread_local_ptr<....
uint64_t id_t
Raw integer type to uniquely identify a thing. 64-bit width should make overflow extremely hard to re...
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
Encapsulates two things: the thread's Tlp_states_map; and what shall run at thread_local deinit.
Global_tl_state()
Ctor: registers (boost::this_thread::at_thread_exit()) a thing that sets s_this_thread_global_tl_stat...
~Global_tl_state()
Dtor that runs at thread_local deinit phase; unknown where among this thread's such deinits this runs...
Tlp_states_map m_tlp_states_map
The heart of the matter.
The data stored in the thread-local class-wide Tlp_states_map, per originating Thread_local_ptr_cache...
void * m_tl_state_ptr
The argument new_value to reset_set(); never null. get() == nullptr means there is no Per_tlp_state.