/src/FreeRDP/winpr/libwinpr/thread/tls.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * WinPR: Windows Portable Runtime |
3 | | * Process Thread Functions |
4 | | * |
5 | | * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #include <winpr/config.h> |
21 | | |
22 | | #include <winpr/handle.h> |
23 | | |
24 | | #include <winpr/thread.h> |
25 | | |
26 | | /** |
27 | | * TlsAlloc |
28 | | * TlsFree |
29 | | * TlsGetValue |
30 | | * TlsSetValue |
31 | | */ |
32 | | |
33 | | #ifndef _WIN32 |
34 | | |
35 | | #include <pthread.h> |
36 | | |
37 | | DWORD TlsAlloc(void) |
38 | 0 | { |
39 | 0 | pthread_key_t key = 0; |
40 | |
|
41 | 0 | if (pthread_key_create(&key, NULL) != 0) |
42 | 0 | return TLS_OUT_OF_INDEXES; |
43 | | |
44 | 0 | return key; |
45 | 0 | } |
46 | | |
47 | | LPVOID TlsGetValue(DWORD dwTlsIndex) |
48 | 0 | { |
49 | 0 | LPVOID value = NULL; |
50 | 0 | pthread_key_t key = 0; |
51 | 0 | key = (pthread_key_t)dwTlsIndex; |
52 | 0 | value = (LPVOID)pthread_getspecific(key); |
53 | 0 | return value; |
54 | 0 | } |
55 | | |
56 | | BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) |
57 | 0 | { |
58 | 0 | pthread_key_t key = 0; |
59 | 0 | key = (pthread_key_t)dwTlsIndex; |
60 | 0 | pthread_setspecific(key, lpTlsValue); |
61 | 0 | return TRUE; |
62 | 0 | } |
63 | | |
64 | | BOOL TlsFree(DWORD dwTlsIndex) |
65 | 0 | { |
66 | 0 | pthread_key_t key = 0; |
67 | 0 | key = (pthread_key_t)dwTlsIndex; |
68 | 0 | pthread_key_delete(key); |
69 | 0 | return TRUE; |
70 | 0 | } |
71 | | |
72 | | #endif |