summaryrefslogtreecommitdiff
path: root/meson-cc-tests/stdatomic-primitives-test.c
diff options
context:
space:
mode:
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-07-12 14:57:49 +0100
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2021-07-20 09:32:52 +0100
commit012ffaac754543eed1d4f4f5de786626f31d5c36 (patch)
tree5d0afa517297fa2aef474a55cff6379b81c2e0cc /meson-cc-tests/stdatomic-primitives-test.c
parentab4761ff8718ce252b4f625a979e0430658a8330 (diff)
downloadfontconfig-012ffaac754543eed1d4f4f5de786626f31d5c36.tar.gz
Add support for C11 stdatomic atomics
This fixes deprecation warnings when building for macOS >= 10.12 systems. Additionally, using stdatomic.h (or the more modern __atomic_ builtins) is required when targeting CHERI-enabled architectures such as CHERI-RISC-V or Arm's Morello since the compiler rejects __sync_* atomic for pointer types (they only work with integers).
Diffstat (limited to 'meson-cc-tests/stdatomic-primitives-test.c')
-rw-r--r--meson-cc-tests/stdatomic-primitives-test.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/meson-cc-tests/stdatomic-primitives-test.c b/meson-cc-tests/stdatomic-primitives-test.c
new file mode 100644
index 0000000..6d11d34
--- /dev/null
+++ b/meson-cc-tests/stdatomic-primitives-test.c
@@ -0,0 +1,8 @@
+#include <stdatomic.h>
+
+void memory_barrier (void) { atomic_thread_fence (memory_order_acq_rel); }
+int atomic_add (atomic_int *i) { return atomic_fetch_add_explicit (i, 1, memory_order_relaxed); }
+int mutex_trylock (atomic_flag *m) { return atomic_flag_test_and_set_explicit (m, memory_order_acquire); }
+void mutex_unlock (atomic_flag *m) { atomic_flag_clear_explicit (m, memory_order_release); }
+
+int main(void) { return 0;}