WG14 threadsafe signals
Toggle main menu visibility
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1
/* Proposed WG14 improved signals support
2
(C) 2024 - 2026 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
// #define WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL 0
21
22
#ifndef WG14_SIGNALS_CONFIG_H
23
#define WG14_SIGNALS_CONFIG_H
24
25
#ifndef WG14_SIGNALS_PREFIX
26
#define WG14_SIGNALS_PREFIX(x) x
27
#endif
28
29
#ifndef WG14_SIGNALS_INLINE
30
#define WG14_SIGNALS_INLINE inline
31
#endif
32
35
#ifndef WG14_SIGNALS_STATIC_ASSERT
36
#ifdef __cplusplus
37
#define WG14_SIGNALS_STATIC_ASSERT(cond, msg) static_assert((cond), msg)
38
#else
39
#define WG14_SIGNALS_STATIC_ASSERT(cond, msg) _Static_assert((cond), msg)
40
#endif
41
#endif
42
43
#ifndef WG14_SIGNALS_THREAD_LOCAL
44
#ifdef __cplusplus
45
#define WG14_SIGNALS_THREAD_LOCAL thread_local
46
#else
47
#define WG14_SIGNALS_THREAD_LOCAL _Thread_local
48
#endif
49
#endif
50
51
#ifndef WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
52
/* https://maskray.me/blog/2021-02-14-all-about-thread-local-storage
53
will tell you all you need to know about TLS implementations and
54
which are async signal safe, and which are not.
55
*/
56
#if (defined(__GNUC__) || defined(_MSC_VER)) && !defined(__APPLE__)
57
#define WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL 1
58
#else
59
#define WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL 0
60
#endif
61
#endif
62
63
#ifndef WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL
64
#if WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
65
#ifdef __GNUC__
66
// ELF needs to use the initial or local exec TLS model to be async signal safe
67
//
68
// WARNING: This can cause issues with this library being loaded dynamically as
69
// part of a runtime loaded shared library!
70
#define WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL \
71
WG14_SIGNALS_THREAD_LOCAL __attribute__((tls_model("initial-exec")))
72
#elif defined(_MSC_VER)
73
// MSVC's thread locals are always async signal safe
74
#define WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL WG14_SIGNALS_THREAD_LOCAL
75
#endif
76
#endif
77
#endif
78
79
#ifndef WG14_SIGNALS_NULLPTR
80
#if __STDC_VERSION__ >= 202300L || __cplusplus
81
#define WG14_SIGNALS_NULLPTR nullptr
82
#else
83
#define WG14_SIGNALS_NULLPTR NULL
84
#endif
85
#endif
86
87
#ifndef WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS
88
#ifdef _MSC_VER
89
#define WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS __declspec(selectany)
90
#else
91
#define WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS __attribute__((weak))
92
#endif
93
#endif
94
95
#ifndef WG14_SIGNALS_DEFAULT_VISIBILITY
96
#ifdef _WIN32
97
#define WG14_SIGNALS_DEFAULT_VISIBILITY
98
#else
99
#define WG14_SIGNALS_DEFAULT_VISIBILITY __attribute__((visibility("default")))
100
#endif
101
#endif
102
103
#ifndef WG14_SIGNALS_ENABLE_HEADER_ONLY
104
#define WG14_SIGNALS_ENABLE_HEADER_ONLY 0
105
#endif
106
107
#ifndef WG14_SIGNALS_EXTERN_IMPL
108
#if WG14_SIGNALS_SOURCE
109
#ifdef _WIN32
110
#define WG14_SIGNALS_EXTERN_IMPL extern __declspec(dllexport)
111
#else
112
#define WG14_SIGNALS_EXTERN_IMPL extern __attribute__((visibility("default")))
113
#endif
114
#else
115
#define WG14_SIGNALS_EXTERN_IMPL extern
116
#endif
117
#endif
118
119
#ifndef WG14_SIGNALS_EXTERN
120
#if WG14_SIGNALS_ENABLE_HEADER_ONLY
121
// Per-TU static inline: an external-linkage inline function may not call the
122
// internal static helpers used by the shared implementation
123
// (-Wstatic-in-inline), and per-TU static definitions avoid duplicate symbols
124
// when the header is included from more than one translation unit (analysis.md
125
// 1.8, C3, Y8, Y10).
126
#define WG14_SIGNALS_EXTERN static WG14_SIGNALS_INLINE
127
#else
128
#define WG14_SIGNALS_EXTERN WG14_SIGNALS_EXTERN_IMPL
129
#endif
130
#endif
131
132
#ifndef WG14_SIGNALS_STDERR_PRINTF
133
#include <stdio.h>
134
#define WG14_SIGNALS_STDERR_PRINTF(...) fprintf(stderr, __VA_ARGS__)
135
#endif
136
137
#ifdef __cplusplus
138
extern
"C"
139
{
140
#endif
141
142
143
#ifdef __cplusplus
144
}
145
#endif
146
147
#endif
include
wg14_signals
config.h
Generated by
1.17.0