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 | --- |
| 11 | .../range/range_tree/lib/portability/toku_atomic.h | 12 ++++++------ |
| 12 | 1 file changed, 6 insertions(+), 6 deletions(-) |
| 13 | |
| 14 | --- a/utilities/transactions/lock/range/range_tree/lib/portability/toku_atomic.h |
| 15 | +++ b/utilities/transactions/lock/range/range_tree/lib/portability/toku_atomic.h |
| 16 | @@ -77,37 +77,37 @@ template <typename T, typename U> |
| 17 | __attribute__((always_inline)) static inline T toku_sync_fetch_and_add(T *addr, |
| 18 | U diff) { |
| 19 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 20 | - return __sync_fetch_and_add(addr, diff); |
| 21 | + return __atomic_fetch_add(addr, diff, 5); |
| 22 | } |
| 23 | template <typename T, typename U> |
| 24 | __attribute__((always_inline)) static inline T toku_sync_add_and_fetch(T *addr, |
| 25 | U diff) { |
| 26 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 27 | - return __sync_add_and_fetch(addr, diff); |
| 28 | + return __atomic_add_fetch(addr, diff, 5); |
| 29 | } |
| 30 | template <typename T, typename U> |
| 31 | __attribute__((always_inline)) static inline T toku_sync_fetch_and_sub(T *addr, |
| 32 | U diff) { |
| 33 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 34 | - return __sync_fetch_and_sub(addr, diff); |
| 35 | + return __atomic_fetch_sub(addr, diff, 5); |
| 36 | } |
| 37 | template <typename T, typename U> |
| 38 | __attribute__((always_inline)) static inline T toku_sync_sub_and_fetch(T *addr, |
| 39 | U diff) { |
| 40 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 41 | - return __sync_sub_and_fetch(addr, diff); |
| 42 | + return __atomic_sub_fetch(addr, diff, 5); |
| 43 | } |
| 44 | template <typename T, typename U, typename V> |
| 45 | __attribute__((always_inline)) static inline T toku_sync_val_compare_and_swap( |
| 46 | T *addr, U oldval, V newval) { |
| 47 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 48 | - return __sync_val_compare_and_swap(addr, oldval, newval); |
| 49 | + return __atomic_compare_exchange(addr, oldval, newval); |
| 50 | } |
| 51 | template <typename T, typename U, typename V> |
| 52 | __attribute__((always_inline)) static inline bool |
| 53 | toku_sync_bool_compare_and_swap(T *addr, U oldval, V newval) { |
| 54 | paranoid_invariant(!crosses_boundary(addr, sizeof *addr)); |
| 55 | - return __sync_bool_compare_and_swap(addr, oldval, newval); |
| 56 | + return static_cast<bool>(__atomic_compare_exchange(addr, oldval, newval)); |
| 57 | } |
| 58 | |
| 59 | // in case you include this but not toku_portability.h |