From f35f85a99ceec7ec92b68c84c843b226793107e1 Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Sat, 30 Aug 2008 21:55:09 +0000 Subject: [PATCH] Added implementation of thread local storage for OS/2. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55384 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/os2/tls.h | 61 ++++++++++++++++++++++++++++++++++++++++++++ include/wx/tls.h | 4 ++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 include/wx/os2/tls.h diff --git a/include/wx/os2/tls.h b/include/wx/os2/tls.h new file mode 100644 index 0000000000..adbfadc409 --- /dev/null +++ b/include/wx/os2/tls.h @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/os2/tls.h +// Purpose: OS/2 implementation of wxTlsValue<> +// Author: Stefan Neis +// Created: 2008-08-30 +// RCS-ID: $Id$ +// Copyright: (c) 2008 Stefan Neis +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_TLS_H_ +#define _WX_MSW_TLS_H_ + +#include "wx/os2/private.h" + +// ---------------------------------------------------------------------------- +// wxTlsKey is a helper class encapsulating a TLS slot +// ---------------------------------------------------------------------------- + +class wxTlsKey +{ +public: + // ctor allocates a new key + wxTlsKey() + { + APIRET rc = ::DosAllocThreadLocalMemory(1, &m_slot); + if (rc != NO_ERROR) + m_slot = NULL; + } + + // return true if the key was successfully allocated + bool IsOk() const { return m_slot != NULL; } + + // get the key value, there is no error return + void *Get() const + { + return (void *)m_slot; + } + + // change the key value, return true if ok + bool Set(void *value) + { + m_slot = (ULONG*)value; + return true; + } + + // free the key + ~wxTlsKey() + { + if ( IsOk() ) + ::DosFreeThreadLocalMemory(m_slot); + } + +private: + ULONG* m_slot; + + DECLARE_NO_COPY_CLASS(wxTlsKey) +}; + +#endif // _WX_MSW_TLS_H_ + diff --git a/include/wx/tls.h b/include/wx/tls.h index 1902716068..7846af1e3b 100644 --- a/include/wx/tls.h +++ b/include/wx/tls.h @@ -46,6 +46,8 @@ #else // !wxHAS_COMPILER_TLS #ifdef __WXMSW__ #include "wx/msw/tls.h" + #elif defined(__OS2__) + #include "wx/os2/tls.h" #elif defined(__UNIX__) #include "wx/unix/tls.h" #else @@ -71,7 +73,7 @@ // there somehow (probably by keeping a list of all TLS objects // and cleaning them up in wxThread cleanup) wxTlsValue() -#ifdef __UNIX__ +#if !defined(__OS2__) && defined(__UNIX__) : m_key(free) #endif { -- 2.49.0