X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/375a5d3a930a38d17fe101d4f395bbc2921c8b67..64a044d5a64dd92473b4cc666a6877db78bd37d3:/include/wx/unix/tls.h diff --git a/include/wx/unix/tls.h b/include/wx/unix/tls.h new file mode 100644 index 0000000000..776494d015 --- /dev/null +++ b/include/wx/unix/tls.h @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/unix/tls.h +// Purpose: Pthreads implementation of wxTlsValue<> +// Author: Vadim Zeitlin +// Created: 2008-08-08 +// RCS-ID: $Id$ +// Copyright: (c) 2008 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_UNIX_TLS_H_ +#define _WX_UNIX_TLS_H_ + +#include "wx/intl.h" +#include "wx/log.h" + +#include + +// ---------------------------------------------------------------------------- +// wxTlsKey is a helper class encapsulating the TLS value index +// ---------------------------------------------------------------------------- + +class wxTlsKey +{ +public: + // ctor allocates a new key + wxTlsKey() + { + int rc = pthread_key_create(&m_key, NULL); + if ( rc ) + wxLogSysError(_("Creating TLS key failed"), rc); + } + + // return true if the key was successfully allocated + bool IsOk() const { return m_key != 0; } + + // get the key value, there is no error return + void *Get() const + { + return pthread_getspecific(m_key); + } + + // change the key value, return true if ok + bool Set(void *value) + { + int rc = pthread_setspecific(m_key, value); + if ( rc ) + { + wxLogSysError(_("Failed to set TLS value")); + return false; + } + + return true; + } + + // free the key + ~wxTlsKey() + { + if ( IsOk() ) + pthread_key_delete(m_key); + } + +private: + pthread_key_t m_key; + + DECLARE_NO_COPY_CLASS(wxTlsKey) +}; + +#endif // _WX_UNIX_TLS_H_ +