1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Pthreads implementation of wxTlsValue<>
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIX_TLS_H_
12 #define _WX_UNIX_TLS_H_
16 // ----------------------------------------------------------------------------
17 // wxTlsKey is a helper class encapsulating the TLS value index
18 // ----------------------------------------------------------------------------
23 // ctor allocates a new key and possibly registering a destructor function
25 wxTlsKey(wxTlsDestructorFunction destructor
)
27 m_destructor
= destructor
;
28 if ( pthread_key_create(&m_key
, destructor
) != 0 )
32 // return true if the key was successfully allocated
33 bool IsOk() const { return m_key
!= 0; }
35 // get the key value, there is no error return
38 return pthread_getspecific(m_key
);
41 // change the key value, return true if ok
48 return pthread_setspecific(m_key
, value
) == 0;
55 pthread_key_delete(m_key
);
59 wxTlsDestructorFunction m_destructor
;
62 wxDECLARE_NO_COPY_CLASS(wxTlsKey
);
65 #endif // _WX_UNIX_TLS_H_