WG14 threadsafe signals
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/>
3File Created: Nov 2024
4
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License in the accompanying file
9Licence.txt or at
10
11http://www.apache.org/licenses/LICENSE-2.0
12
13Unless required by applicable law or agreed to in writing, software
14distributed under the License is distributed on an "AS IS" BASIS,
15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16See the License for the specific language governing permissions and
17limitations 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
28extern "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#ifdef _WIN32
40 static
41#else
43#endif
44 WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL WG14_SIGNALS_PREFIX(thread_id_t)
45 WG14_SIGNALS_PREFIX(current_thread_id_cached);
46#endif
47
48 WG14_SIGNALS_EXTERN WG14_SIGNALS_PREFIX(thread_id_t)
49 WG14_SIGNALS_PREFIX(internal_current_thread_id_cached_set)(void);
50
52 static WG14_SIGNALS_INLINE WG14_SIGNALS_PREFIX(thread_id_t)
53 WG14_SIGNALS_PREFIX(current_thread_id)(void)
54 {
55#if WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
56 if(WG14_SIGNALS_PREFIX(current_thread_id_cached) ==
57 WG14_SIGNALS_PREFIX(thread_id_t_tombstone))
58 {
59 WG14_SIGNALS_PREFIX(current_thread_id_cached) =
60 WG14_SIGNALS_PREFIX(internal_current_thread_id_cached_set)();
61 }
62 return WG14_SIGNALS_PREFIX(current_thread_id_cached);
63#else
64 return WG14_SIGNALS_PREFIX(internal_current_thread_id_cached_set)();
65#endif
66 }
67
68#ifdef __cplusplus
69}
70#endif
71
72#endif
#define WG14_SIGNALS_INLINE
Definition config.h:30
#define WG14_SIGNALS_EXTERN
Definition config.h:85
uintptr_t thread_id_t
The type of a thread id.
thread_id_t internal_current_thread_id_cached_set(void)