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