summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct5
-rw-r--r--build.txt19
-rw-r--r--compiler.h10
3 files changed, 22 insertions, 12 deletions
diff --git a/SConstruct b/SConstruct
index 9006f5c6..a942cfba 100644
--- a/SConstruct
+++ b/SConstruct
@@ -634,6 +634,11 @@ else:
else:
confdefs.append("/* #undef HAVE_TERMIOS_H */\n")
+ if config.CheckHeader("stdatomic.h"):
+ confdefs.append("#define HAVE_STDATOMIC_H 1\n")
+ else:
+ confdefs.append("/* #undef HAVE_STDATOMIC_H */\n")
+
# endian.h is required for rtcm104v2 unless the compiler defines
# __ORDER_BIG_ENDIAN__, __ORDER_LITTLE_ENDIAN__ and __BYTE_ORDER__
if config.CheckCompilerDefines("__ORDER_BIG_ENDIAN__") \
diff --git a/build.txt b/build.txt
index 41f0c7db..811b6adc 100644
--- a/build.txt
+++ b/build.txt
@@ -58,10 +58,17 @@ arrange this by putting symlink in a local directory on $PATH.
=== C compiler ===
C99 conformance is required in the compiler. The C code depends on one
-non-C99 feature (supported by GCC, clang, and pretty much any C
-compiler that also speaks C++): anonymous unions. We could eliminate
-these, but the cost would be source-level interface breakage if we
-have to move structure members in and out of unions.
+C11 feature (supported by GCC, clang, and pretty much any C compiler
+that also speaks C++): anonymous unions. We could eliminate these,
+but the cost would be source-level interface breakage if we have to
+move structure members in and out of unions.
+
+Some portions of the code using shared-memory segments are improved by
+the C11 stdatomic.h features for lockless concurrency. These are: the
+SHM export mode in shmexport.c, the code for writing clock corrections
+to NTP in ntpshm.c, and the code for reading NTP corrections in
+ntpshmread.c. These features have been supported in GCC since 4.7 and
+clang since 3.1.
GPSD is normally built and tested with GCC. Do not compile with a version
older than 4.1.1; there are several known issues with older versions,
@@ -71,9 +78,7 @@ generation, (c) the option -Wno-missing-field-initializers is
unavailable, leading to a flood of warnings (this is due to generated
code and cannot be fixed).
-The shared-memory interface relies on one GCCism, but the code is
-otherwise pretty compiler-agnostic. It is reported that clang
-produces a gpsd that passes all regression tests.
+clang produces a gpsd that passes all regression tests.
=== Python ===
diff --git a/compiler.h b/compiler.h
index bd73808a..f46b05f0 100644
--- a/compiler.h
+++ b/compiler.h
@@ -7,6 +7,8 @@
#ifndef _GPSD_COMPILER_H_
#define _GPSD_COMPILER_H_
+#include "gpsd_config.h" /* is STD_ATOMIC_H defined? */
+
/* Macro for declaring function with printf-like arguments. */
# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
#define PRINTF_FUNC(format_index, arg_index) \
@@ -32,11 +34,9 @@
static /*@unused@*/ inline void memory_barrier(void)
{
#ifndef S_SPLINT_S
-#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
- __atomic_thread_fence(__ATOMIC_SEQ_CST);
-#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
- __sync_synchronize();
-#endif
+#ifdef STD_ATOMIC_H
+ atomic_thread_fence(memory_order_seq_cst);
+#endif /* STD_ATOMIC_H */
#endif /* S_SPLINT_S */
}