30# define CVC4_THREADLOCAL(__type...) __type
31# define CVC4_THREADLOCAL_PUBLIC(__type...) CVC4_PUBLIC __type
32# define CVC4_THREADLOCAL_TYPE(__type...) __type
35# define CVC4_THREADLOCAL(__type...) ::CVC4::ThreadLocal< __type >
36# define CVC4_THREADLOCAL_PUBLIC(__type...) CVC4_PUBLIC ::CVC4::ThreadLocal< __type >
37# define CVC4_THREADLOCAL_TYPE(__type...) ::CVC4::ThreadLocal< __type >
41template <
class T,
bool small>
48 static void cleanup(
void*) {
53 pthread_key_create(&d_key, ThreadLocalImpl::cleanup);
57 pthread_key_create(&d_key, ThreadLocalImpl::cleanup);
58 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(t)));
62 pthread_key_create(&d_key, ThreadLocalImpl::cleanup);
63 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(
static_cast<const T&
>(tl))));
67 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(t)));
71 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(
static_cast<const T&
>(tl))));
76 return static_cast<T
>(
reinterpret_cast<size_t>(pthread_getspecific(d_key)));
84 static void cleanup(
void*) {
89 pthread_key_create(&d_key, ThreadLocalImpl::cleanup);
93 pthread_key_create(&d_key, ThreadLocalImpl::cleanup);
94 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(t)));
98 pthread_key_create(&d_key, ThreadLocalImpl::cleanup);
99 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(
static_cast<const T*
>(tl))));
103 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(t)));
107 pthread_setspecific(d_key,
const_cast<void*
>(
reinterpret_cast<const void*
>(
static_cast<const T*
>(tl))));
111 operator T*()
const {
112 return static_cast<T*
>(pthread_getspecific(d_key));
116 return *
static_cast<T*
>(pthread_getspecific(d_key));
119 return static_cast<T*
>(pthread_getspecific(d_key));
128class ThreadLocal :
public ThreadLocalImpl<T, sizeof(T) <= sizeof(void*)> {
129 typedef ThreadLocalImpl<T, sizeof(T) <= sizeof(void*)> super;
132 ThreadLocal() : super() {}
133 ThreadLocal(const T& t) : super(t) {}
134 ThreadLocal(const ThreadLocal<T>& tl) : super(tl) {}
136 ThreadLocal<T>& operator=(const T& t) {
137 return static_cast< ThreadLocal<T>& >(super::operator=(t));
139 ThreadLocal<T>& operator=(const ThreadLocal<T>& tl) {
140 return static_cast< ThreadLocal<T>& >(super::operator=(tl));
145class ThreadLocal<T*> : public ThreadLocalImpl<T*, sizeof(T*) <= sizeof(void*)> {
146 typedef ThreadLocalImpl<T*, sizeof(T*) <= sizeof(void*)> super;
149 ThreadLocal() : super() {}
150 ThreadLocal(T* t) : super(t) {}
151 ThreadLocal(const ThreadLocal<T*>& tl) : super(tl) {}
153 ThreadLocal<T*>& operator=(T* t) {
154 return static_cast< ThreadLocal<T*>& >(super::operator=(t));
156 ThreadLocal<T*>& operator=(const ThreadLocal<T*>& tl) {
157 return static_cast< ThreadLocal<T*>& >(super::operator=(tl));
161 return *static_cast<T*>(*this);
163 const T& operator*() const {
164 return *static_cast<const T*>(*this);
167 return static_cast<T*>(*this);
169 const T* operator->() const {
170 return static_cast<const T*>(*this);
ThreadLocalImpl(const ThreadLocalImpl &tl)
ThreadLocalImpl & operator=(const ThreadLocalImpl &tl)
ThreadLocalImpl(const T &t)
ThreadLocalImpl & operator=(const T &t)
ThreadLocalImpl(const ThreadLocalImpl &tl)
ThreadLocalImpl(const T *t)
ThreadLocalImpl & operator=(const ThreadLocalImpl &tl)
ThreadLocalImpl & operator=(const T *t)
Macros that should be defined everywhere during the building of the libraries and driver binary,...