1 #ifndef SimTK_SimTKCOMMON_THREAD_LOCAL_H_ 2 #define SimTK_SimTKCOMMON_THREAD_LOCAL_H_ 79 explicit ThreadLocal(
const T& defaultValue) : m_defaultValue(defaultValue) {
87 pthread_key_delete(m_key);
93 T* value =
reinterpret_cast<T*
>(pthread_getspecific(m_key));
95 value = createValue();
101 const T&
get()
const {
102 T* value =
reinterpret_cast<T*
>(pthread_getspecific(m_key));
104 value = createValue();
113 static void cleanUpThreadLocalStorage(
void* value) {
114 T* t =
reinterpret_cast<T*
>(value);
119 pthread_key_create(&m_key, cleanUpThreadLocalStorage);
122 T* createValue()
const {
123 T* value =
new T(m_defaultValue);
124 pthread_setspecific(m_key, value);
134 #endif // SimTK_SimTKCOMMON_THREAD_LOCAL_H_ (Deprecated) This class represents a "thread local" variable: one which may have a different value on...
Definition: ThreadLocal.h:63
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
T & upd()
Get a writable reference to the value of type T that was allocated for the current thread's exclusive...
Definition: ThreadLocal.h:92
ThreadLocal(const T &defaultValue)
Create a new ThreadLocal<T> object and provide a default value of type T to be used to initialize the...
Definition: ThreadLocal.h:79
~ThreadLocal()
Destructor deletes the thread local object but does not delete the individual thread-allocated object...
Definition: ThreadLocal.h:86
ThreadLocal()
Create a new ThreadLocal<T> object.
Definition: ThreadLocal.h:68