Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add atomic support #261

Merged
merged 8 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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