From 3d079f67aa1bec733d668fb116e09a509bd806db Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Tue, 8 Mar 2022 11:21:37 +0100 Subject: [PATCH] add atomic support (#261) --- CMakeLists.txt | 1 + include/re_atomic.h | 37 +++++++++++++++++++++++++++++++++++++ mk/re.mk | 3 +-- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 include/re_atomic.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d1377116..6193da497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ if(CMAKE_USE_PTHREADS_INIT) endif() add_definitions( + -DHAVE_ATOMIC -DHAVE_INET6 -DHAVE_SELECT ) diff --git a/include/re_atomic.h b/include/re_atomic.h new file mode 100644 index 000000000..a73cc76da --- /dev/null +++ b/include/re_atomic.h @@ -0,0 +1,37 @@ +/** + * @file re_atomic.h Atomic support + * + * Copyright (C) 2022 Sebastian Reimers + */ + +#ifndef RE_H_ATOMIC__ +#define RE_H_ATOMIC__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* C11 */ +#ifdef HAVE_ATOMIC +#include + +/* C99 */ +#elif defined(__clang__) +#define __CLANG_ATOMICS + +#elif defined(__GNUC__) +#if __GNUC_PREREQ(4, 9) +#define __SYNC_ATOMICS +#else +#error "Atomic requires gcc >= 4.9" +#endif /* __GNUC_PREREQ */ + +#else +#error "Your compiler does not support atomics" +#endif /* HAVE_ATOMIC */ + +#ifdef __cplusplus +} +#endif + +#endif /* RE_H_ATOMIC__ */ diff --git a/mk/re.mk b/mk/re.mk index 9b5f92687..0528ae73d 100644 --- a/mk/re.mk +++ b/mk/re.mk @@ -339,10 +339,9 @@ CFLAGS += -std=c11 HAVE_ATOMIC := 1 endif -CFLAGS += -pedantic - ifneq ($(HAVE_ATOMIC),) CFLAGS += -DHAVE_ATOMIC +CFLAGS += -pedantic endif