Nebula
Loading...
Searching...
No Matches
posixthreadlocalptr.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
bool isvalid() const
test if content is valid
pthread_key_t key
Definition osxthreadlocalptr.h:41
~OSXThreadLocalPtr()
destructor
void set(TYPE *p)
set content
TYPE * get() const
get content
#define n_assert(exp)
Definition debug.h:50
Definition osxsysfunc.h:21