template sprawl::threading::ThreadLocal::ThreadLocal() { pthread_key_create(&m_key, NULL); } template sprawl::threading::ThreadLocal::ThreadLocal(T const& value) { pthread_key_create(&m_key, NULL); set(value); } template sprawl::threading::ThreadLocal::~ThreadLocal() { pthread_key_delete(m_key); } template T* sprawl::threading::ThreadLocal::get() { return reinterpret_cast(pthread_getspecific(m_key)); } template T const* sprawl::threading::ThreadLocal::get() const { return reinterpret_cast(pthread_getspecific(m_key)); } template void sprawl::threading::ThreadLocal::set(T const& value) { T* oldValue = reinterpret_cast(pthread_getspecific(m_key)); if(oldValue) { *oldValue = value; } else { pthread_setspecific(m_key, (void*)(new T(value))); } } template sprawl::threading::ThreadLocal::ThreadLocal() { pthread_key_create(&m_key, NULL); } template sprawl::threading::ThreadLocal::ThreadLocal(T const* value) { pthread_key_create(&m_key, NULL); set(value); } template sprawl::threading::ThreadLocal::~ThreadLocal() { pthread_key_delete(m_key); } template T* sprawl::threading::ThreadLocal::get() { return reinterpret_cast(pthread_getspecific(m_key)); } template T const* sprawl::threading::ThreadLocal::get() const { return reinterpret_cast(pthread_getspecific(m_key)); } template void sprawl::threading::ThreadLocal::set(T const* value) { pthread_setspecific(m_key, (void*)(value)); }