path: root/lib
diff options
authorKefu Chai <>2021-08-11 12:29:39 +0800
committerKefu Chai <>2021-08-26 00:10:56 +0800
commit33ab69055ce3c8c78d487452e7b82ce303251455 (patch)
tree1a42c2dc4a4237ea02db043385de095bfffbfc7a /lib
parent15ce99bb71e7c289f62ddee94e0149f6c81549de (diff)
arch,lib/seqlock: implement seqlock with C++ atomic if compiled with C++
because some functions declared by <stdatomic.h> share the same names with those declared by <atomic>, for instance `kill_dependency()` is defined as a macro by <stdatomic.h>, while it is defined as a template function in <atomic>. this renders it impossible to compile an ioengine written in C++ if its source file includes both <atomic> and <fio.h>. the latter includes <stdatomic.h> via arch/arch.h. the compile error would look like: In file included from ../src/test/fio/ In file included from src/fio/fio.h:18: In file included from src/fio/thread_options.h:8: In file included from src/fio/gettime.h:7: src/fio/lib/seqlock.h:21:9: error: expected ')' seq = atomic_load_acquire(&s->sequence); ^ src/fio/arch/../lib/../arch/arch.h:47:32: note: expanded from macro 'atomic_load_acquire' atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \ ^ src/fio/lib/seqlock.h:21:9: note: to match this '(' to address this issue, instead of using the functions in <stdatomic.h> to implement seqlock, use the primitives offered by C++ standard library if the source code is compiled using a C++ compiler. Signed-off-by: Kefu Chai <>
Diffstat (limited to 'lib')
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/seqlock.h b/lib/seqlock.h
index 56f3e37d..ef3aa091 100644
--- a/lib/seqlock.h
+++ b/lib/seqlock.h
@@ -5,7 +5,11 @@
#include "../arch/arch.h"
struct seqlock {
+#ifdef __cplusplus
+ std::atomic<unsigned int> sequence;
volatile unsigned int sequence;
static inline void seqlock_init(struct seqlock *s)