50template <
typename Type>
62 for (
auto* o = first.
get(); o !=
nullptr;)
82 operator Type*()
const noexcept {
return &
get(); }
99 Type&
get() const noexcept
102 ObjectHolder* o =
nullptr;
104 for (o = first.
get(); o !=
nullptr; o = o->next)
105 if (o->threadId.get() == threadId)
108 for (o = first.
get(); o !=
nullptr; o = o->next)
109 if (o->threadId.compareAndSetBool (threadId,
nullptr))
115 for (o =
new ObjectHolder (threadId, first.
get());
117 o->next = first.
get());
129 for (
auto* o = first.
get(); o !=
nullptr; o = o->next)
130 if (o->threadId.compareAndSetBool (
nullptr, threadId))
138 ObjectHolder (
Thread::ThreadID idToUse, ObjectHolder* n) : threadId (idToUse), next (n), object() {}
140 Atomic<Thread::ThreadID> threadId;
144 JUCE_DECLARE_NON_COPYABLE (ObjectHolder)
147 mutable Atomic<ObjectHolder*> first;
149 JUCE_DECLARE_NON_COPYABLE (ThreadLocalValue)
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...