FreeRDP
Loading...
Searching...
No Matches
winpr/libwinpr/thread/tls.c
1
20#include <winpr/config.h>
21
22#include <winpr/handle.h>
23
24#include <winpr/thread.h>
25
33#ifndef _WIN32
34
35#include <pthread.h>
36
37DWORD TlsAlloc(void)
38{
39 pthread_key_t key = 0;
40
41 if (pthread_key_create(&key, nullptr) != 0)
42 return TLS_OUT_OF_INDEXES;
43 if (key > UINT32_MAX)
44 return TLS_OUT_OF_INDEXES;
45 return WINPR_ASSERTING_INT_CAST(DWORD, key);
46}
47
48LPVOID TlsGetValue(DWORD dwTlsIndex)
49{
50 pthread_key_t key = (pthread_key_t)dwTlsIndex;
51 return (LPVOID)pthread_getspecific(key);
52}
53
54BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
55{
56 pthread_key_t key = (pthread_key_t)dwTlsIndex;
57 pthread_setspecific(key, lpTlsValue);
58 return TRUE;
59}
60
61BOOL TlsFree(DWORD dwTlsIndex)
62{
63 pthread_key_t key = (pthread_key_t)dwTlsIndex;
64 pthread_key_delete(key);
65 return TRUE;
66}
67
68#endif