Andrew Geissler | 6972109 | 2021-07-23 12:57:00 -0400 | [diff] [blame] | 1 | From 114c42fba3fc86119710e8dd1bb2b7a9e39e3064 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Thu, 17 Jun 2021 19:35:01 -0700 |
| 4 | Subject: [PATCH] replace old sync with new atomic builtin equivalents |
| 5 | |
| 6 | Helps compiling with gcc on newer arches e.g. riscv32 where these |
| 7 | __sync* builtins are not implemented atleast for 64bit values |
| 8 | |
| 9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 10 | --- |
Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 11 | Upstream-Status: Pending |
| 12 | |
Andrew Geissler | 6972109 | 2021-07-23 12:57:00 -0400 | [diff] [blame] | 13 | .../range/range_tree/lib/portability/toku_atomic.h | 12 ++++++------ |
| 14 | 1 file changed, 6 insertions(+), 6 deletions(-) |
| 15 | |
| 16 | --- a/utilities/transactions/lock/range/range_tree/lib/portability/toku_atomic.h |
| 17 | +++ b/utilities/transactions/lock/range/range_tree/lib/portability/toku_atomic.h |
| 18 | @@ -77,37 +77,37 @@ template <typename T, typename U> |
| 19 | __attribute__((always_inline)) static inline T toku_sync_fetch_and_add(T *addr, |
| 20 | U diff) { |
| 21 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 22 | - return __sync_fetch_and_add(addr, diff); |
| 23 | + return __atomic_fetch_add(addr, diff, 5); |
| 24 | } |
| 25 | template <typename T, typename U> |
| 26 | __attribute__((always_inline)) static inline T toku_sync_add_and_fetch(T *addr, |
| 27 | U diff) { |
| 28 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 29 | - return __sync_add_and_fetch(addr, diff); |
| 30 | + return __atomic_add_fetch(addr, diff, 5); |
| 31 | } |
| 32 | template <typename T, typename U> |
| 33 | __attribute__((always_inline)) static inline T toku_sync_fetch_and_sub(T *addr, |
| 34 | U diff) { |
| 35 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 36 | - return __sync_fetch_and_sub(addr, diff); |
| 37 | + return __atomic_fetch_sub(addr, diff, 5); |
| 38 | } |
| 39 | template <typename T, typename U> |
| 40 | __attribute__((always_inline)) static inline T toku_sync_sub_and_fetch(T *addr, |
| 41 | U diff) { |
| 42 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 43 | - return __sync_sub_and_fetch(addr, diff); |
| 44 | + return __atomic_sub_fetch(addr, diff, 5); |
| 45 | } |
| 46 | template <typename T, typename U, typename V> |
| 47 | __attribute__((always_inline)) static inline T toku_sync_val_compare_and_swap( |
| 48 | T *addr, U oldval, V newval) { |
| 49 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 50 | - return __sync_val_compare_and_swap(addr, oldval, newval); |
| 51 | + return __atomic_compare_exchange(addr, oldval, newval); |
| 52 | } |
| 53 | template <typename T, typename U, typename V> |
| 54 | __attribute__((always_inline)) static inline bool |
| 55 | toku_sync_bool_compare_and_swap(T *addr, U oldval, V newval) { |
| 56 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 57 | - return __sync_bool_compare_and_swap(addr, oldval, newval); |
| 58 | + return static_cast<bool>(__atomic_compare_exchange(addr, oldval, newval)); |
| 59 | } |
| 60 | |
| 61 | // in case you include this but not toku_portability.h |