]> git.saurik.com Git - wxWidgets.git/blob - include/wx/tls.h
Minor corrections to make dist after reports
[wxWidgets.git] / include / wx / tls.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/tls.h
3 // Purpose: Implementation of thread local storage
4 // Author: Vadim Zeitlin
5 // Created: 2008-08-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_TLS_H_
12 #define _WX_TLS_H_
13
14 #include "wx/defs.h"
15
16 // ----------------------------------------------------------------------------
17 // check for compiler support of thread-specific variables
18 // ----------------------------------------------------------------------------
19
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)
26 #endif
27
28 // ----------------------------------------------------------------------------
29 // define wxTLS_TYPE()
30 // ----------------------------------------------------------------------------
31
32 #ifdef wxHAS_COMPILER_TLS
33 #define wxTLS_TYPE(T) wxTHREAD_SPECIFIC_DECL T
34 #else // !wxHAS_COMPILER_TLS
35 #ifdef __WXMSW__
36 #include "wx/msw/tls.h"
37 #elif defined(__UNIX__)
38 #include "wx/unix/tls.h"
39 #else
40 // TODO: we could emulate TLS for such platforms...
41 #error Neither compiler nor OS support thread-specific variables.
42 #endif
43
44 // wxTlsValue<T> represents a thread-specific value of type T
45 template <typename T>
46 class wxTlsValue
47 {
48 public:
49 typedef T ValueType;
50
51 wxTlsValue() { *this = static_cast<T>(0); }
52
53 wxTlsValue& operator=(T value)
54 {
55 m_key.Set(wxUIntToPtr(value));
56
57 return *this;
58 }
59
60 operator T() const { return wxPtrToUInt(m_key.Get()); }
61
62 private:
63 wxTlsKey m_key;
64
65 DECLARE_NO_COPY_TEMPLATE_CLASS(wxTlsValue, T)
66 };
67
68 #define wxTLS_TYPE(T) wxTlsValue<T>
69 #endif // wxHAS_COMPILER_TLS/!wxHAS_COMPILER_TLS
70
71 #endif // _WX_TLS_H_
72