Non‐templated base holding the shared thread‐local bookkeeping state.
Synopsis
Declared in <folly/detail/ThreadLocalDetail.h>
struct StaticMetaBase;
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. |
Type Aliases
Name |
Description |
A ThreadEntrySet guarded by a synchronization wrapper. |
Member Functions
Name |
Description |
|
Constructs the base with a thread‐entry accessor and access mode. |
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 calling thread's list of thread entries. |
|
Thread‐exit callback that disposes the thread's entries. |
|
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. |
Derived Classes
Name |
Description |
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). |
Created with MrDocs