Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
osxthreadlocalptr.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
21
#include "
core/types.h
"
22
23
//------------------------------------------------------------------------------
24
namespace
OSX
25
{
26
template
<
typename
TYPE>
27
class
OSXThreadLocalPtr
28
{
29
public
:
31
OSXThreadLocalPtr
();
33
~OSXThreadLocalPtr
();
35
void
set
(TYPE* p);
37
TYPE*
get
()
const
;
39
bool
isvalid
()
const
;
40
private
:
41
pthread_key_t
key
;
42
};
43
44
//------------------------------------------------------------------------------
47
template
<
typename
TYPE>
48
OSXThreadLocalPtr<TYPE>::OSXThreadLocalPtr
() :
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
//------------------------------------------------------------------------------
59
template
<
typename
TYPE>
60
OSXThreadLocalPtr<TYPE>::~OSXThreadLocalPtr
()
61
{
62
int
res = pthread_key_delete(this->
key
);
63
n_assert
(0 == res);
64
this->
key
= 0;
65
}
66
67
//------------------------------------------------------------------------------
70
template
<
typename
TYPE>
void
71
OSXThreadLocalPtr<TYPE>::set
(TYPE* p)
72
{
73
pthread_setspecific(this->
key
, p);
74
}
75
76
//------------------------------------------------------------------------------
79
template
<
typename
TYPE> TYPE*
80
OSXThreadLocalPtr<TYPE>::get
()
const
81
{
82
return
(TYPE*) pthread_getspecific(this->
key
);
83
}
84
85
//------------------------------------------------------------------------------
88
template
<
typename
TYPE>
bool
89
OSXThreadLocalPtr<TYPE>::isvalid
()
const
90
{
91
return
(0 != pthread_getspecific(this->
key
));
92
}
93
94
}
// namespace OSX
95
//------------------------------------------------------------------------------
OSX::OSXThreadLocalPtr::OSXThreadLocalPtr
OSXThreadLocalPtr()
default constructor
Definition
osxthreadlocalptr.h:48
OSX::OSXThreadLocalPtr::isvalid
bool isvalid() const
test if content is valid
Definition
osxthreadlocalptr.h:89
OSX::OSXThreadLocalPtr::key
pthread_key_t key
Definition
osxthreadlocalptr.h:41
OSX::OSXThreadLocalPtr::~OSXThreadLocalPtr
~OSXThreadLocalPtr()
destructor
Definition
osxthreadlocalptr.h:60
OSX::OSXThreadLocalPtr::set
void set(TYPE *p)
set content
Definition
osxthreadlocalptr.h:71
OSX::OSXThreadLocalPtr::get
TYPE * get() const
get content
Definition
osxthreadlocalptr.h:80
n_assert
#define n_assert(exp)
Definition
debug.h:50
OSX
Definition
osxsysfunc.h:21
types.h
code
foundation
threading
osx
osxthreadlocalptr.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.