Nebula
Loading...
Searching...
No Matches
osxthreadlocalptr.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
21#include "core/types.h"
22
23//------------------------------------------------------------------------------
24namespace OSX
25{
26template<typename TYPE>
27class OSXThreadLocalPtr
28{
29public:
35 void set(TYPE* p);
37 TYPE* get() const;
39 bool isvalid() const;
40private:
41 pthread_key_t key;
42};
43
44//------------------------------------------------------------------------------
47template<typename TYPE>
49 key(0)
50{
51 int res = pthread_key_create(&this->key, NULL);
52 n_assert(0 == res);
53 pthread_setspecific(this->key, 0);
54}
55
56//------------------------------------------------------------------------------
59template<typename TYPE>
61{
62 int res = pthread_key_delete(this->key);
63 n_assert(0 == res);
64 this->key = 0;
65}
66
67//------------------------------------------------------------------------------
70template<typename TYPE> void
72{
73 pthread_setspecific(this->key, p);
74}
75
76//------------------------------------------------------------------------------
79template<typename TYPE> TYPE*
81{
82 return (TYPE*) pthread_getspecific(this->key);
83}
84
85//------------------------------------------------------------------------------
88template<typename TYPE> bool
90{
91 return (0 != pthread_getspecific(this->key));
92}
93
94} // namespace OSX
95//------------------------------------------------------------------------------
OSXThreadLocalPtr()
default constructor
Definition osxthreadlocalptr.h:48
bool isvalid() const
test if content is valid
Definition osxthreadlocalptr.h:89
pthread_key_t key
Definition osxthreadlocalptr.h:41
~OSXThreadLocalPtr()
destructor
Definition osxthreadlocalptr.h:60
void set(TYPE *p)
set content
Definition osxthreadlocalptr.h:71
TYPE * get() const
get content
Definition osxthreadlocalptr.h:80
#define n_assert(exp)
Definition debug.h:50
Definition osxsysfunc.h:21