Message ID | 1560401339-31537-1-git-send-email-guru@ovn.org |
---|---|
State | Accepted |
Commit | 35736cff1901eab5b33892ff053f02d5d87cb8c1 |
Headers | show |
Series | [ovs-dev] ovs-atomic-c++.h: Fix for 64 bit atomics. | expand |
On Wed, Jun 12, 2019 at 09:48:59PM -0700, Gurucharan Shetty wrote: > Commit e981a45a6cae4 (ovs-atomic: Add 64 bit apis.) > added a few 64 bit apis (e.g: atomic_count_inc64). For C++, > this invokes std::atomic_fetch_*_explicit() functions in > lib/ovs-atomic-c++.h. > > The function overloading for 64 bit function fails without > specifiying something like: std::atomic_fetch_*_explicit<std::uint64_t>(). > But it looks tricky to do this with macros. > > This patch tries to fix the compilation failures by calling atomic > functions on the variables itself. > > Signed-off-by: Gurucharan Shetty <guru@ovn.org> If this works (I did not test it) then it looks nicer than the previous code. Thank you! Acked-by: Ben Pfaff <blp@ovn.org>
On Thu, 13 Jun 2019 at 09:54, Ben Pfaff <blp@ovn.org> wrote: > On Wed, Jun 12, 2019 at 09:48:59PM -0700, Gurucharan Shetty wrote: > > Commit e981a45a6cae4 (ovs-atomic: Add 64 bit apis.) > > added a few 64 bit apis (e.g: atomic_count_inc64). For C++, > > this invokes std::atomic_fetch_*_explicit() functions in > > lib/ovs-atomic-c++.h. > > > > The function overloading for 64 bit function fails without > > specifiying something like: > std::atomic_fetch_*_explicit<std::uint64_t>(). > > But it looks tricky to do this with macros. > > > > This patch tries to fix the compilation failures by calling atomic > > functions on the variables itself. > > > > Signed-off-by: Gurucharan Shetty <guru@ovn.org> > > If this works (I did not test it) then it looks nicer than the previous > code. Thank you! > > Acked-by: Ben Pfaff <blp@ovn.org> > Thank you. I tested this and pushed to master.
diff --git a/lib/ovs-atomic-c++.h b/lib/ovs-atomic-c++.h index 949e4ff..d47b8dd 100644 --- a/lib/ovs-atomic-c++.h +++ b/lib/ovs-atomic-c++.h @@ -47,15 +47,15 @@ using std::atomic_compare_exchange_weak_explicit; atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst) #define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \ - (*(ORIG) = std::atomic_fetch_add_explicit(RMW, ARG, ORDER), (void) 0) + (*(ORIG) = (*(RMW)).fetch_add(ARG, ORDER), (void) 0) #define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \ - (*(ORIG) = std::atomic_fetch_sub_explicit(RMW, ARG, ORDER), (void) 0) + (*(ORIG) = (*(RMW)).fetch_sub(ARG, ORDER), (void) 0) #define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \ - (*(ORIG) = std::atomic_fetch_or_explicit(RMW, ARG, ORDER), (void) 0) + (*(ORIG) = (*(RMW)).fetch_or(ARG, ORDER), (void) 0) #define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \ - (*(ORIG) = std::atomic_fetch_xor_explicit(RMW, ARG, ORDER), (void) 0) + (*(ORIG) = (*(RMW)).fetch_xor(ARG, ORDER), (void) 0) #define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \ - (*(ORIG) = std::atomic_fetch_and_explicit(RMW, ARG, ORDER), (void) 0) + (*(ORIG) = (*(RMW)).fetch_and(ARG, ORDER), (void) 0) using std::atomic_flag; using std::atomic_flag_test_and_set_explicit;
Commit e981a45a6cae4 (ovs-atomic: Add 64 bit apis.) added a few 64 bit apis (e.g: atomic_count_inc64). For C++, this invokes std::atomic_fetch_*_explicit() functions in lib/ovs-atomic-c++.h. The function overloading for 64 bit function fails without specifiying something like: std::atomic_fetch_*_explicit<std::uint64_t>(). But it looks tricky to do this with macros. This patch tries to fix the compilation failures by calling atomic functions on the variables itself. Signed-off-by: Gurucharan Shetty <guru@ovn.org> --- lib/ovs-atomic-c++.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)