1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Pthreads implementation of wxTlsValue<>
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_UNIX_TLS_H_
11 #define _WX_UNIX_TLS_H_
15 // ----------------------------------------------------------------------------
16 // wxTlsKey is a helper class encapsulating the TLS value index
17 // ----------------------------------------------------------------------------
22 // ctor allocates a new key and possibly registering a destructor function
24 wxTlsKey(wxTlsDestructorFunction destructor
)
26 m_destructor
= destructor
;
27 if ( pthread_key_create(&m_key
, destructor
) != 0 )
31 // return true if the key was successfully allocated
32 bool IsOk() const { return m_key
!= 0; }
34 // get the key value, there is no error return
37 return pthread_getspecific(m_key
);
40 // change the key value, return true if ok
47 return pthread_setspecific(m_key
, value
) == 0;
54 pthread_key_delete(m_key
);
58 wxTlsDestructorFunction m_destructor
;
61 wxDECLARE_NO_COPY_CLASS(wxTlsKey
);
64 #endif // _WX_UNIX_TLS_H_