Skip to content

Commit

Permalink
add atomic support (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored Mar 8, 2022
1 parent 04a6ec9 commit 3d079f6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ if(CMAKE_USE_PTHREADS_INIT)
endif()

add_definitions(
-DHAVE_ATOMIC
-DHAVE_INET6
-DHAVE_SELECT
)
Expand Down
37 changes: 37 additions & 0 deletions include/re_atomic.h
Original file line number Diff line number Diff line change
@@ -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 <stdatomic.h>

/* 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__ */
3 changes: 1 addition & 2 deletions mk/re.mk
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,9 @@ CFLAGS += -std=c11
HAVE_ATOMIC := 1
endif

CFLAGS += -pedantic

ifneq ($(HAVE_ATOMIC),)
CFLAGS += -DHAVE_ATOMIC
CFLAGS += -pedantic
endif


Expand Down

0 comments on commit 3d079f6

Please sign in to comment.