// Purpose: Pthreads implementation of wxTlsValue<>
// Author: Vadim Zeitlin
// Created: 2008-08-08
-// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
{
public:
// ctor allocates a new key and possibly registering a destructor function
- // for it (notice that using destructor function is Pthreads-specific and
- // not supported in Win32 implementation)
- wxTlsKey(void (*destructor)(void *) = NULL)
+ // for it
+ wxTlsKey(wxTlsDestructorFunction destructor)
{
+ m_destructor = destructor;
if ( pthread_key_create(&m_key, destructor) != 0 )
m_key = 0;
}
// change the key value, return true if ok
bool Set(void *value)
{
+ void *old = Get();
+ if ( old )
+ m_destructor(old);
+
return pthread_setspecific(m_key, value) == 0;
}
}
private:
+ wxTlsDestructorFunction m_destructor;
pthread_key_t m_key;
- DECLARE_NO_COPY_CLASS(wxTlsKey)
+ wxDECLARE_NO_COPY_CLASS(wxTlsKey);
};
#endif // _WX_UNIX_TLS_H_