summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKefu Chai <tchaikov@gmail.com>2021-08-11 12:29:39 +0800
committerKefu Chai <tchaikov@gmail.com>2021-08-26 00:10:56 +0800
commit33ab69055ce3c8c78d487452e7b82ce303251455 (patch)
tree1a42c2dc4a4237ea02db043385de095bfffbfc7a /lib
parent15ce99bb71e7c289f62ddee94e0149f6c81549de (diff)
downloadfio-33ab69055ce3c8c78d487452e7b82ce303251455.tar.gz
fio-33ab69055ce3c8c78d487452e7b82ce303251455.tar.bz2
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/fio_ceph_objectstore.cc:26: 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 <tchaikov@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/seqlock.h4
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;
+#else
volatile unsigned int sequence;
+#endif
};
static inline void seqlock_init(struct seqlock *s)