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
37#if !defined(WITHOUT_WINPR_3x_DEPRECATED)
38
39DWORD TlsAlloc(void)
40{
41 pthread_key_t key = 0;
42
43 if (pthread_key_create(&key, nullptr) != 0)
44 return TLS_OUT_OF_INDEXES;
45 if (key > UINT32_MAX)
46 return TLS_OUT_OF_INDEXES;
47 return WINPR_ASSERTING_INT_CAST(DWORD, key);
48}
49
50LPVOID TlsGetValue(DWORD dwTlsIndex)
51{
52 pthread_key_t key = (pthread_key_t)dwTlsIndex;
53 return (LPVOID)pthread_getspecific(key);
54}
55
56BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
57{
58 pthread_key_t key = (pthread_key_t)dwTlsIndex;
59 pthread_setspecific(key, lpTlsValue);
60 return TRUE;
61}
62
63BOOL TlsFree(DWORD dwTlsIndex)
64{
65 pthread_key_t key = (pthread_key_t)dwTlsIndex;
66 pthread_key_delete(key);
67 return TRUE;
68}
69
70#endif
71
72#endif