X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/64a044d5a64dd92473b4cc666a6877db78bd37d3..9869c26285dc51d13607cddaa04f65ce983653a5:/include/wx/unix/tls.h diff --git a/include/wx/unix/tls.h b/include/wx/unix/tls.h index 776494d015..ce61e6fff7 100644 --- a/include/wx/unix/tls.h +++ b/include/wx/unix/tls.h @@ -3,7 +3,6 @@ // Purpose: Pthreads implementation of wxTlsValue<> // Author: Vadim Zeitlin // Created: 2008-08-08 -// RCS-ID: $Id$ // Copyright: (c) 2008 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -11,9 +10,6 @@ #ifndef _WX_UNIX_TLS_H_ #define _WX_UNIX_TLS_H_ -#include "wx/intl.h" -#include "wx/log.h" - #include // ---------------------------------------------------------------------------- @@ -23,12 +19,13 @@ class wxTlsKey { public: - // ctor allocates a new key - wxTlsKey() + // ctor allocates a new key and possibly registering a destructor function + // for it + wxTlsKey(wxTlsDestructorFunction destructor) { - int rc = pthread_key_create(&m_key, NULL); - if ( rc ) - wxLogSysError(_("Creating TLS key failed"), rc); + m_destructor = destructor; + if ( pthread_key_create(&m_key, destructor) != 0 ) + m_key = 0; } // return true if the key was successfully allocated @@ -43,14 +40,11 @@ public: // change the key value, return true if ok bool Set(void *value) { - int rc = pthread_setspecific(m_key, value); - if ( rc ) - { - wxLogSysError(_("Failed to set TLS value")); - return false; - } + void *old = Get(); + if ( old ) + m_destructor(old); - return true; + return pthread_setspecific(m_key, value) == 0; } // free the key @@ -61,9 +55,10 @@ public: } private: + wxTlsDestructorFunction m_destructor; pthread_key_t m_key; - DECLARE_NO_COPY_CLASS(wxTlsKey) + wxDECLARE_NO_COPY_CLASS(wxTlsKey); }; #endif // _WX_UNIX_TLS_H_