C++20 report error at file rte_spinlock.h
Konstantin Ananyev
konstantin.ananyev at huawei.com
Mon Dec 19 17:51:22 CET 2022
> On Tue, Dec 13, 2022 at 06:11:06AM +0000, Zhou, Xiangyun wrote:
> > Dear dpdk dev,
> >
> > I'm using dpdk 21.11 LTS, when compile my program with CPP flag "-std=c++20", the compiler report below errors. After checking file
> rte_spinlock.h, I think the error report by compiler is valid, there should be a potential issue when using functions
> rte_spinlock_recursive_lock, rte_spinlock_recursive_unlock and rte_spinlock_recursive_trylock in multi-thread, we could either
> remove "volatile" definition to ask users to handle the multi-thread issue, or using atomic operatings instead of self-increment and
> self-decrement.
> >
> >
> > /home/dpdk/lib/eal/include/generic/rte_spinlock.h:221:12: error: increment of object of volatile-qualified type 'volatile int' is
> deprecated [-Werror,-Wdeprecated-volatile]
> > slr->count++;
> > ^
> > /home/dpdk/lib/eal/include/generic/rte_spinlock.h:231:6: error: decrement of object of volatile-qualified type 'volatile int' is
> deprecated [-Werror,-Wdeprecated-volatile]
> > if (--(slr->count) == 0) {
> > ^
> > /home/dpdk/lib/eal/include/generic/rte_spinlock.h:255:12: error: increment of object of volatile-qualified type 'volatile int' is
> deprecated [-Werror,-Wdeprecated-volatile]
> > slr->count++;
> >
>
> i have work in progress to optionally use standard atomics but in the
> meantime the correct thing to do here is to use the gcc builtins that
> match the requirements of the c++11 memory model.
>
> the code should be converted to use __atomic_fetch_{add,sub} or
> __atomic_{add,sub}_fetch as appropriate.
>
> ty.
>From looking at the code, I don't think it is necessary:
both 'user' and 'count' supposed to be protected by 'sl'.
In fact, it looks safe just to remove 'volatile' qualifier here.
More information about the dev
mailing list