WG14 threadsafe signals
Toggle main menu visibility
Loading...
Searching...
No Matches
current_thread_id.h
Go to the documentation of this file.
1
/* Proposed WG14 improved signals support
2
(C) 2024 Niall Douglas <http://www.nedproductions.biz/>
3
File Created: Nov 2024
4
5
6
Licensed under the Apache License, Version 2.0 (the "License");
7
you may not use this file except in compliance with the License.
8
You may obtain a copy of the License in the accompanying file
9
Licence.txt or 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
#ifndef WG14_SIGNALS_GET_TID_H
21
#define WG14_SIGNALS_GET_TID_H
22
23
#include "
config.h
"
24
25
#include <stdint.h>
26
27
#ifdef __cplusplus
28
extern
"C"
29
{
30
#endif
31
33
typedef
uintptr_t WG14_SIGNALS_PREFIX(
thread_id_t
);
34
35
static
const
WG14_SIGNALS_PREFIX(
thread_id_t
)
36
WG14_SIGNALS_PREFIX(thread_id_t_tombstone) = 0;
37
38
#if WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
39
// If this platform has async signal safe thread locals, we can cache the thread
40
// id in an inlineable variable.
41
#ifdef _WIN32
42
// On Windows thread local vars can't be dllexported, so cache per DLL
43
extern
WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS
44
#elif WG14_SIGNALS_ENABLE_HEADER_ONLY
45
WG14_SIGNALS_EXTERN_IMPL
46
WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS
47
#else
48
WG14_SIGNALS_EXTERN
49
#endif
50
WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL WG14_SIGNALS_PREFIX(
thread_id_t
)
51
WG14_SIGNALS_PREFIX(current_thread_id_cached);
52
#endif
53
54
WG14_SIGNALS_EXTERN
WG14_SIGNALS_PREFIX(
thread_id_t
)
55
WG14_SIGNALS_PREFIX(
internal_current_thread_id_cached_set
)(
void
);
56
58
static
WG14_SIGNALS_INLINE
WG14_SIGNALS_PREFIX(
thread_id_t
)
59
WG14_SIGNALS_PREFIX(current_thread_id)(
void
)
60
{
61
#if WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
62
if
(WG14_SIGNALS_PREFIX(current_thread_id_cached) ==
63
WG14_SIGNALS_PREFIX(thread_id_t_tombstone))
64
{
65
WG14_SIGNALS_PREFIX(current_thread_id_cached) =
66
WG14_SIGNALS_PREFIX(
internal_current_thread_id_cached_set
)();
67
}
68
return
WG14_SIGNALS_PREFIX(current_thread_id_cached);
69
#else
70
return
WG14_SIGNALS_PREFIX(
internal_current_thread_id_cached_set
)();
71
#endif
72
}
73
74
#ifdef __cplusplus
75
}
76
#endif
77
78
#if WG14_SIGNALS_ENABLE_HEADER_ONLY
79
#include "detail/impl/current_thread_id.c.ipp"
80
#endif
81
82
#endif
config.h
WG14_SIGNALS_INLINE
#define WG14_SIGNALS_INLINE
Definition
config.h:30
WG14_SIGNALS_EXTERN
#define WG14_SIGNALS_EXTERN
Definition
config.h:113
WG14_SIGNALS_EXTERN_IMPL
#define WG14_SIGNALS_EXTERN_IMPL
Definition
config.h:105
WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS
#define WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS
Definition
config.h:81
thread_id_t
uintptr_t thread_id_t
The type of a thread id.
Definition
current_thread_id.h:33
internal_current_thread_id_cached_set
thread_id_t internal_current_thread_id_cached_set(void)
include
wg14_signals
current_thread_id.h
Generated by
1.17.0