arch,lib/seqlock: implement seqlock with C++ atomic if compiled with C++
authorKefu Chai <tchaikov@gmail.com>
Wed, 11 Aug 2021 04:29:39 +0000 (12:29 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 25 Aug 2021 16:10:56 +0000 (00:10 +0800)
commit33ab69055ce3c8c78d487452e7b82ce303251455
tree1a42c2dc4a4237ea02db043385de095bfffbfc7a
parent15ce99bb71e7c289f62ddee94e0149f6c81549de
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>
arch/arch.h
lib/seqlock.h