]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/tls.h
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
24 // for it (notice that using destructor function is Pthreads-specific and
25 // not supported in Win32 implementation)
26 wxTlsKey(void (*destructor
)(void *) = NULL
)
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
44 return pthread_setspecific(m_key
, value
) == 0;
51 pthread_key_delete(m_key
);
57 wxDECLARE_NO_COPY_CLASS(wxTlsKey
);
60 #endif // _WX_UNIX_TLS_H_