Held in a singleton to track our global instances. We have one of these per "Tag", by default one for the whole system (Tag=void).
Synopsis
Declared in <folly/detail/ThreadLocalDetail.h>
template<
class Tag,
class AccessMode>
struct StaticMeta final
: StaticMetaBase
Description
Creating and destroying ThreadLocalPtr objects, as well as thread exit for threads that use ThreadLocalPtr objects collide on a lock inside StaticMeta; you can specify multiple Tag types to break that lock.
Base Classes
Name |
Description |
Non‐templated base holding the shared thread‐local bookkeeping state. |
Types
Name |
Description |
Represents an ID of a thread local object. Initially set to the maximum uint. This representation allows us to avoid a branch in accessing TLS data (because if you test capacity > id if id = maxint then the test will always fail). It allows us to keep a constexpr constructor and avoid SIOF. |
|
Per‐thread cache of the current thread entry and its capacity. |
Type Aliases
Name |
Description |
A ThreadEntrySet guarded by a synchronization wrapper. |
Member Functions
Name |
Description |
|
Constructs the singleton and registers its fork handlers. |
Allocates a slot id for the given entry. |
|
Allocates a new thread entry for the calling thread. |
|
Frees the slot id owned by the given entry. |
|
Returns the elementsCapacity for the current thread ThreadEntry struct. |
|
Ensure the given ThreadEntry* is present in the tracking set for the given id. Once added, we do not remove it until the thread exits or the whole set is reaped when the TL id itself is destroyed. |
|
Returns the element wrapper for the given entry on the current thread. |
|
Returns a span over the pointers to all active thread entry sets. |
|
Return true if given ThreadEntry is already present in the ThreadEntrySet for the given id. |
|
Check if ThreadEntry* is present in the map for all slots of ids. |
|
Pop current ThreadEntrySet and for each ThreadEntry in it, clear its ElementWrapper for the 'id' and return them in the accumulated vector. This is called when an TL object is destroyed. The ElementWrapper returned are the responsibility of the calling thread to dispose of. |
|
Remove a ThreadEntry* from the map of allId2ThreadEntrySets_ for all slot |
|
Reserve enough space in the ThreadEntry::elements for the item |
Static Member Functions
Name |
Description |
Helper to do final free and delete of ThreadEntry and ThreadEntryList structures. |
|
Reports whether the process is in thread‐local teardown. |
|
Returns the element wrapper for the given entry on the current thread. |
|
Returns the calling thread's local cache. |
|
Reserves the entry's slot and refreshes the local cache. |
|
Returns the calling thread's entry for the given id. |
|
Returns the calling thread's list of thread entries. |
|
Returns the calling thread's entry, allocating it on first use. |
|
Returns the thread entry, reserving capacity for the entry's slot. |
|
Returns the process‐wide singleton for this tag and access mode. |
|
Fork child handler; keeps only the surviving thread's entries. |
|
Fork parent handler; releases the locks taken in preFork(). |
|
Thread‐exit callback that disposes the thread's entries. |
|
Fork prepare handler; acquires the locks needed across fork. |
|
Static helper method to reallocate the ThreadEntry::elements. |
Data Members
Name |
Description |
Guards accessAllThreads() against concurrent per‐thread resets. |
|
This is a map of all thread entries mapped to index i with active elements[i]; |
|
Serializes fork handling against all thread‐entry‐set locking. |
|
The pool of freed slot ids available for reuse. |
|
The lock_ is used to protect the freeIds_ list as well as synchronize reallocation of a thread's private array of ElementWrappers. The freeIds_ vector is manipulated on TL object id allocation and destroy. Resize of ElementWrappers array can only be done by its owner thread but other threads may try to be accessing the array at the same time if in the middle of destroying a TL object. |
|
The next slot id to allocate. |
|
The pthread key backing per‐thread entry storage. |
|
Whether strict access mode is enabled. |
|
Function returning the calling thread's entry. |
|
Total size of ElementWrapper arrays across all threads. This is meant to surface the overhead of thread local tracking machinery since the array can be sparse when there are lots of thread local variables under the same tag. |
Static Data Members
Name |
Description |
Whether native thread‐local storage is used on this platform. |
Created with MrDocs