Coverage Report

Created: 2026-07-16 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/winpr/libwinpr/thread/tls.c
Line
Count
Source
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, nullptr) != 0)
42
0
    return TLS_OUT_OF_INDEXES;
43
0
  if (key > UINT32_MAX)
44
0
    return TLS_OUT_OF_INDEXES;
45
0
  return WINPR_ASSERTING_INT_CAST(DWORD, key);
46
0
}
47
48
LPVOID TlsGetValue(DWORD dwTlsIndex)
49
0
{
50
0
  pthread_key_t key = (pthread_key_t)dwTlsIndex;
51
0
  return (LPVOID)pthread_getspecific(key);
52
0
}
53
54
BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
55
0
{
56
0
  pthread_key_t key = (pthread_key_t)dwTlsIndex;
57
0
  pthread_setspecific(key, lpTlsValue);
58
0
  return TRUE;
59
0
}
60
61
BOOL TlsFree(DWORD dwTlsIndex)
62
0
{
63
0
  pthread_key_t key = (pthread_key_t)dwTlsIndex;
64
0
  pthread_key_delete(key);
65
0
  return TRUE;
66
0
}
67
68
#endif