]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/tls.h
derive wxStandardPathsCF from Unix wxStandardPaths implementation to make it possible...
[wxWidgets.git] / include / wx / unix / tls.h
CommitLineData
64a044d5
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/unix/tls.h
3// Purpose: Pthreads 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_UNIX_TLS_H_
12#define _WX_UNIX_TLS_H_
13
64a044d5
VZ
14#include <pthread.h>
15
16// ----------------------------------------------------------------------------
17// wxTlsKey is a helper class encapsulating the TLS value index
18// ----------------------------------------------------------------------------
19
20class wxTlsKey
21{
22public:
8b73c531
VZ
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)
64a044d5 27 {
8b73c531
VZ
28 if ( pthread_key_create(&m_key, destructor) != 0 )
29 m_key = 0;
64a044d5
VZ
30 }
31
32 // return true if the key was successfully allocated
33 bool IsOk() const { return m_key != 0; }
34
35 // get the key value, there is no error return
36 void *Get() const
37 {
38 return pthread_getspecific(m_key);
39 }
40
41 // change the key value, return true if ok
42 bool Set(void *value)
43 {
8b73c531 44 return pthread_setspecific(m_key, value) == 0;
64a044d5
VZ
45 }
46
47 // free the key
48 ~wxTlsKey()
49 {
50 if ( IsOk() )
51 pthread_key_delete(m_key);
52 }
53
54private:
55 pthread_key_t m_key;
56
c0c133e1 57 wxDECLARE_NO_COPY_CLASS(wxTlsKey);
64a044d5
VZ
58};
59
60#endif // _WX_UNIX_TLS_H_
61