46template <
typename Type>
58 for (
auto* o = first.
get(); o !=
nullptr;)
78 operator Type*()
const noexcept {
return &
get(); }
95 Type&
get() const noexcept
98 ObjectHolder* o =
nullptr;
100 for (o = first.
get(); o !=
nullptr; o = o->next)
101 if (o->threadId.get() == threadId)
104 for (o = first.
get(); o !=
nullptr; o = o->next)
105 if (o->threadId.compareAndSetBool (threadId,
nullptr))
111 for (o =
new ObjectHolder (threadId, first.
get());
113 o->next = first.
get());
125 for (
auto* o = first.
get(); o !=
nullptr; o = o->next)
126 if (o->threadId.compareAndSetBool (
nullptr, threadId))
134 ObjectHolder (
Thread::ThreadID idToUse, ObjectHolder* n) : threadId (idToUse), next (n), object() {}
136 Atomic<Thread::ThreadID> threadId;
143 mutable Atomic<ObjectHolder*> first;
Provides cross-platform support for thread-local objects.
Type & operator*() const noexcept
Returns a reference to this thread's instance of the value.
Type * operator->() const noexcept
Accesses a method or field of the value object.
void releaseCurrentThreadStorage()
Called by a thread before it terminates, to allow this class to release any storage associated with t...
Type & get() const noexcept
Returns a reference to this thread's instance of the value.
ThreadLocalValue & operator=(const Type &newValue)
Assigns a new value to the thread-local object.
~ThreadLocalValue()
Destructor.
void * ThreadID
A value type used for thread IDs.
static ThreadID JUCE_CALLTYPE getCurrentThreadId()
Returns an id that identifies the caller thread.
Type get() const noexcept
Atomically reads and returns the current value.
bool compareAndSetBool(Type newValue, Type valueToCompare) noexcept
Atomically compares this value with a target value, and if it is equal, sets this to be equal to a ne...