]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/tls.h
9d1d6373b3e2da265a5f8413ca7bb2371afd17f9
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implementation of thread local storage
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
16 // ----------------------------------------------------------------------------
17 // check for compiler support of thread-specific variables
18 // ----------------------------------------------------------------------------
20 #ifdef HAVE___THREAD_KEYWORD
21 #define wxHAS_COMPILER_TLS
22 #define wxTHREAD_SPECIFIC_DECL __thread
23 #elif wxCHECK_VISUALC_VERSION(7)
24 #define wxHAS_COMPILER_TLS
25 #define wxTHREAD_SPECIFIC_DECL __declspec(thread)
28 // ----------------------------------------------------------------------------
29 // define wxTLS_TYPE()
30 // ----------------------------------------------------------------------------
32 #ifdef wxHAS_COMPILER_TLS
33 #define wxTLS_TYPE(T) wxTHREAD_SPECIFIC_DECL T
34 #else // !wxHAS_COMPILER_TLS
36 #include "wx/msw/tls.h"
37 #elif defined(__UNIX__)
38 #include "wx/unix/tls.h"
40 // TODO: we could emulate TLS for such platforms...
41 #error Neither compiler nor OS support thread-specific variables.
44 // wxTlsValue<T> represents a thread-specific value of type T
51 wxTlsValue() { *this = static_cast<T
>(0); }
53 wxTlsValue
& operator=(T value
)
55 m_key
.Set(wxUIntToPtr(value
));
60 operator T() const { return wxPtrToUInt(m_key
.Get()); }
65 DECLARE_NO_COPY_TEMPLATE_CLASS(wxTlsValue
, T
)
68 #define wxTLS_TYPE(T) wxTlsValue<T>
69 #endif // wxHAS_COMPILER_TLS/!wxHAS_COMPILER_TLS