-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththreadctx.cpp
60 lines (44 loc) · 873 Bytes
/
threadctx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "threadctx.h"
#ifdef _WIN32
#include <windows.h>
namespace GC
{
ThreadContextImpl::ThreadContextImpl()
{
key = TlsAlloc();
}
ThreadContextImpl::~ThreadContextImpl()
{
TlsFree(key);
}
void* ThreadContextImpl::get()
{
return TlsGetValue(key);
}
void ThreadContextImpl::set(void* value)
{
TlsSetValue(key, value);
}
};
#else
#include <pthread.h>
namespace GC
{
ThreadContextImpl::ThreadContextImpl()
{
pthread_key_create(&key, NULL);
}
ThreadContextImpl::~ThreadContextImpl()
{
pthread_key_delete(key);
}
void* ThreadContextImpl::get()
{
return pthread_getspecific(key);
}
void ThreadContextImpl::set(void* value)
{
pthread_setspecific(key, value);
}
};
#endif