From: José Fonseca Date: Tue, 23 Apr 2013 08:45:02 +0000 (+0100) Subject: os: Simplify os::thread_specific_ptr. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=fbc23dc3c4699b1bbf17cc3c987e4c85857a3614;p=apitrace os: Simplify os::thread_specific_ptr. Instead of mimicking boost::thread_specific_ptr, do something that allows to mimick more closely compiler TLS support. --- diff --git a/common/os_thread.hpp b/common/os_thread.hpp index 5ec7f5d..da6e106 100644 --- a/common/os_thread.hpp +++ b/common/os_thread.hpp @@ -26,7 +26,7 @@ /* * OS native thread abstraction. * - * Mimics C++11 / boost threads. + * Mimics C++11 threads. */ #ifndef _OS_THREAD_HPP_ @@ -283,9 +283,6 @@ namespace os { }; - /** - * Same interface as boost::thread_specific_ptr. - */ template class thread_specific_ptr { @@ -294,10 +291,6 @@ namespace os { DWORD dwTlsIndex; #else pthread_key_t key; - - static void destructor(void *ptr) { - delete static_cast(ptr); - } #endif public: @@ -305,7 +298,7 @@ namespace os { #ifdef _WIN32 dwTlsIndex = TlsAlloc(); #else - pthread_key_create(&key, &destructor); + pthread_key_create(&key, NULL); #endif } @@ -317,7 +310,8 @@ namespace os { #endif } - T* get(void) const { + inline T * + get(void) const { void *ptr; #ifdef _WIN32 ptr = TlsGetValue(dwTlsIndex); @@ -327,32 +321,27 @@ namespace os { return static_cast(ptr); } - T* operator -> (void) const + inline + operator T * (void) const { return get(); } - T& operator * (void) const + inline T * + operator -> (void) const { - return *get(); + return get(); } - void reset(T* new_value=0) { - T * old_value = get(); + inline T * + operator = (T * new_value) + { set(new_value); - if (old_value) { - delete old_value; - } + return new_value; } - T* release (void) { - T * old_value = get(); - set(0); - return old_value; - } - -private: - void set(T* new_value) { + inline void + set(T* new_value) { #ifdef _WIN32 TlsSetValue(dwTlsIndex, new_value); #else