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