]>
Commit | Line | Data |
---|---|---|
64a044d5 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/unix/tls.h | |
3 | // Purpose: Win32 implementation of wxTlsValue<> | |
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_MSW_TLS_H_ | |
12 | #define _WX_MSW_TLS_H_ | |
13 | ||
14 | #include "wx/log.h" | |
15 | ||
16 | #include "wx/msw/wrapwin.h" | |
17 | ||
18 | // ---------------------------------------------------------------------------- | |
19 | // wxTlsKey is a helper class encapsulating a TLS slot | |
20 | // ---------------------------------------------------------------------------- | |
21 | ||
22 | class wxTlsKey | |
23 | { | |
24 | public: | |
25 | // ctor allocates a new key | |
26 | wxTlsKey() | |
27 | { | |
28 | m_slot = ::TlsAlloc(); | |
29 | if ( m_slot == TLS_OUT_OF_INDEXES ) | |
30 | wxLogError("Creating TLS key failed"); | |
31 | } | |
32 | ||
33 | // return true if the key was successfully allocated | |
34 | bool IsOk() const { return m_slot != TLS_OUT_OF_INDEXES; } | |
35 | ||
36 | // get the key value, there is no error return | |
37 | void *Get() const | |
38 | { | |
39 | return ::TlsGetValue(m_slot); | |
40 | } | |
41 | ||
42 | // change the key value, return true if ok | |
43 | bool Set(void *value) | |
44 | { | |
45 | if ( !::TlsSetValue(m_slot, value) ) | |
46 | { | |
47 | wxLogSysError(_("Failed to set TLS value")); | |
48 | return false; | |
49 | } | |
50 | ||
51 | return true; | |
52 | } | |
53 | ||
54 | // free the key | |
55 | ~wxTlsKey() | |
56 | { | |
57 | if ( IsOk() ) | |
58 | { | |
59 | if ( !::TlsFree(m_slot) ) | |
60 | { | |
61 | wxLogDebug("TlsFree() failed: %08x", ::GetLastError()); | |
62 | } | |
63 | } | |
64 | } | |
65 | ||
66 | private: | |
67 | DWORD m_slot; | |
68 | ||
69 | DECLARE_NO_COPY_CLASS(wxTlsKey) | |
70 | }; | |
71 | ||
72 | #endif // _WX_MSW_TLS_H_ | |
73 |