WG14 threadsafe signals
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/>
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// #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
33#ifndef WG14_SIGNALS_THREAD_LOCAL
34#ifdef __cplusplus
35#define WG14_SIGNALS_THREAD_LOCAL thread_local
36#else
37#define WG14_SIGNALS_THREAD_LOCAL _Thread_local
38#endif
39#endif
40
41#ifndef WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
42/* https://maskray.me/blog/2021-02-14-all-about-thread-local-storage
43will tell you all you need to know about TLS implementations and
44which are async signal safe, and which are not.
45*/
46#if(defined(__GNUC__) || defined(_MSC_VER)) && !defined(__APPLE__)
47#define WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL 1
48#else
49#define WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL 0
50#endif
51#endif
52
53#ifndef WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL
54#if WG14_SIGNALS_HAVE_ASYNC_SAFE_THREAD_LOCAL
55#ifdef __GNUC__
56// ELF needs to use the initial or local exec TLS model to be async signal safe
57//
58// WARNING: This can cause issues with this library being loaded dynamically as
59// part of a runtime loaded shared library!
60#define WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL \
61 WG14_SIGNALS_THREAD_LOCAL __attribute__((tls_model("initial-exec")))
62#elif defined(_MSC_VER)
63// MSVC's thread locals are always async signal safe
64#define WG14_SIGNALS_ASYNC_SAFE_THREAD_LOCAL WG14_SIGNALS_THREAD_LOCAL
65#endif
66#endif
67#endif
68
69#ifndef WG14_SIGNALS_NULLPTR
70#if __STDC_VERSION__ >= 202300L
71#define WG14_SIGNALS_NULLPTR nullptr
72#else
73#define WG14_SIGNALS_NULLPTR NULL
74#endif
75#endif
76
77#ifndef WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS
78#ifdef _MSC_VER
79#define WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS __declspec(selectany)
80#else
81#define WG14_SIGNALS_IGNORE_MULTIPLE_DEFINITIONS __attribute__((weak))
82#endif
83#endif
84
85#ifndef WG14_SIGNALS_DEFAULT_VISIBILITY
86#ifdef _WIN32
87#define WG14_SIGNALS_DEFAULT_VISIBILITY
88#else
89#define WG14_SIGNALS_DEFAULT_VISIBILITY __attribute__((visibility("default")))
90#endif
91#endif
92
93#ifndef WG14_SIGNALS_ENABLE_HEADER_ONLY
94#define WG14_SIGNALS_ENABLE_HEADER_ONLY 0
95#endif
96
97#ifndef WG14_SIGNALS_EXTERN_IMPL
98#if WG14_SIGNALS_SOURCE
99#ifdef _WIN32
100#define WG14_SIGNALS_EXTERN_IMPL extern __declspec(dllexport)
101#else
102#define WG14_SIGNALS_EXTERN_IMPL extern __attribute__((visibility("default")))
103#endif
104#else
105#define WG14_SIGNALS_EXTERN_IMPL extern
106#endif
107#endif
108
109#ifndef WG14_SIGNALS_EXTERN
110#if WG14_SIGNALS_ENABLE_HEADER_ONLY
111#define WG14_SIGNALS_EXTERN WG14_SIGNALS_INLINE
112#else
113#define WG14_SIGNALS_EXTERN WG14_SIGNALS_EXTERN_IMPL
114#endif
115#endif
116
117#ifndef WG14_SIGNALS_STDERR_PRINTF
118#include <stdio.h>
119#define WG14_SIGNALS_STDERR_PRINTF(...) fprintf(stderr, __VA_ARGS__)
120#endif
121
122#ifdef __cplusplus
123extern "C"
124{
125#endif
126
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif