gwnavruntime/basesystem/threadlocalstorage.h Source File
Go to the documentation of this file.
8 #ifndef Navigation_ThreadLocalStorage_H
9 #define Navigation_ThreadLocalStorage_H
13 #if defined (KY_OS_XBOX360)
14 #define KY_THREAD_LOCAL __declspec(thread)
15 #elif defined (KY_OS_WII)
16 #define KY_THREAD_LOCAL
17 #elif defined (KY_OS_MAC) || defined (KY_OS_IPHONE)
18 #define KY_THREAD_LOCAL
21 #define KY_THREAD_LOCAL __thread
32 #if defined (KY_OS_WIN32)
37 static unsigned long KyTlsAlloc();
38 static void* KyTlsGetValue(
unsigned long dwTlsIndex);
39 static int KyTlsSetValue(
unsigned long dwTlsIndex,
void* lpTlsValue);
40 static int KyTlsFree(
unsigned long dwTlsIndex);
44 template<
typename ptrT>
class ThreadLocalStorageWrapper
48 ThreadLocalStorageWrapper() { m_tlsIdx = (
KyUInt32)WinTls::KyTlsAlloc(); }
49 ~ThreadLocalStorageWrapper() { WinTls::KyTlsFree(m_tlsIdx); }
50 inline ptrT Get() {
return (ptrT)WinTls::KyTlsGetValue(m_tlsIdx); }
51 inline void Set(ptrT ptr) { WinTls::KyTlsSetValue(m_tlsIdx, (
void*)ptr); }
59 #elif defined (KY_OS_MAC) || defined (KY_OS_IPHONE)
61 template<
typename ptrT>
class ThreadLocalStorageWrapper
65 ThreadLocalStorageWrapper() { pthread_key_create(&m_key,
KY_NULL); }
66 ~ThreadLocalStorageWrapper() { pthread_key_delete(m_key); }
67 inline ptrT Get() {
return (ptrT) pthread_getspecific(m_key); }
68 inline void Set(ptrT ptr) { pthread_setspecific(m_key, (
void*)ptr ); }
79 template<
typename ptrT>
class ThreadLocalStorageWrapper
83 ThreadLocalStorageWrapper() {}
84 ~ThreadLocalStorageWrapper() {}
85 inline ptrT Get() {
return TlsInstance(); }
86 inline void Set(ptrT ptr) { TlsInstance() = ptr; }
88 inline ptrT& TlsInstance() {
static KY_THREAD_LOCAL ptrT s_ptr;
return s_ptr; }
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36