Skip to content

Commit 8f6de54

Browse files
authored
Merge pull request #230 from ptrrsn/atomic
Fix the atomicity of cy_atomic_int
2 parents fbfc559 + 94c382a commit 8f6de54

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

meson.build

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ config.set('CYSIGNALS_USE_SIGSETJMP', (setjmp_saves_mask or gnulibc) ? 1 : 0)
8282

8383
# Check for atomic operations
8484
# for _Atomic in C code
85-
config.set('CYSIGNALS_C_ATOMIC', cc.links('static _Atomic int x;') ? 1 : 0)
85+
config.set('CYSIGNALS_C_ATOMIC', cc.links('int main(void) { static _Atomic int x; return 0; }') ? 1 : 0)
8686
# for _Atomic with OpenMP in C code
87-
config.set('CYSIGNALS_C_ATOMIC_WITH_OPENMP', cc.links('static _Atomic int x;', args: ['-fopenmp']) ? 1 : 0)
87+
config.set('CYSIGNALS_C_ATOMIC_WITH_OPENMP', cc.links('int main(void) { static _Atomic int x; return 0; }', args: ['-fopenmp']) ? 1 : 0)
8888
# for _Atomic in C++ code
89-
config.set('CYSIGNALS_CXX_ATOMIC', cxx.links('static _Atomic int x;') ? 1 : 0)
89+
config.set('CYSIGNALS_CXX_ATOMIC', cxx.links('int main() { static _Atomic int x; return 0; }') ? 1 : 0)
9090
# for _Atomic with OpenMP in C++ code
91-
config.set('CYSIGNALS_CXX_ATOMIC_WITH_OPENMP', cxx.links('static _Atomic int x;', args: ['-fopenmp']) ? 1 : 0)
91+
config.set('CYSIGNALS_CXX_ATOMIC_WITH_OPENMP', cxx.links('int main() { static _Atomic int x; return 0; }', args: ['-fopenmp']) ? 1 : 0)
9292
# for std::atomic in C++ code
93-
config.set('CYSIGNALS_STD_ATOMIC', cxx.links('#include <atomic>\nstatic std::atomic<int> x;') ? 1 : 0)
93+
config.set('CYSIGNALS_STD_ATOMIC', cxx.links('#include <atomic>\nint main() { static std::atomic<int> x; return 0; }') ? 1 : 0)
9494
# for std::atomic with OpenMP in C++ code
95-
config.set('CYSIGNALS_STD_ATOMIC_WITH_OPENMP', cxx.links('#include <atomic>\nstatic std::atomic<int> x;', args: ['-fopenmp']) ? 1 : 0)
95+
config.set('CYSIGNALS_STD_ATOMIC_WITH_OPENMP', cxx.links('#include <atomic>\nint main() { static std::atomic<int> x; return 0; }', args: ['-fopenmp']) ? 1 : 0)
9696

9797
if is_windows
9898
threads_dep = []

src/cysignals/struct_signals.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@
4141

4242

4343
/* Define a cy_atomic_int type for atomic operations */
44-
#if CYSIGNALS_C_ATOMIC || CYSIGNALS_CXX_ATOMIC
45-
typedef volatile _Atomic int cy_atomic_int;
46-
#elif CYSIGNALS_STD_ATOMIC
44+
#if __cplusplus
45+
#if CYSIGNALS_STD_ATOMIC
4746
#include <atomic>
4847
typedef volatile std::atomic<int> cy_atomic_int;
48+
#elif CYSIGNALS_CXX_ATOMIC
49+
typedef volatile _Atomic int cy_atomic_int;
4950
#else
5051
/* The type sig_atomic_t is not really atomic, but it's the best we have */
5152
typedef volatile sig_atomic_t cy_atomic_int;
5253
#endif
54+
#else
55+
#if CYSIGNALS_C_ATOMIC
56+
typedef volatile _Atomic int cy_atomic_int;
57+
#else
58+
/* The type sig_atomic_t is not really atomic, but it's the best we have */
59+
typedef volatile sig_atomic_t cy_atomic_int;
60+
#endif
61+
#endif
5362

5463

5564
/* All the state of the signal handler is in this struct. */

0 commit comments

Comments
 (0)