diff options
Diffstat (limited to 'src/third_party/wiredtiger/src/include/gcc.h')
-rw-r--r-- | src/third_party/wiredtiger/src/include/gcc.h | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/src/third_party/wiredtiger/src/include/gcc.h b/src/third_party/wiredtiger/src/include/gcc.h index 043d9b44356..deae5bf06a9 100644 --- a/src/third_party/wiredtiger/src/include/gcc.h +++ b/src/third_party/wiredtiger/src/include/gcc.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014-2017 MongoDB, Inc. + * Copyright (c) 2014-2018 MongoDB, Inc. * Copyright (c) 2008-2014 WiredTiger, Inc. * All rights reserved. * @@ -94,61 +94,76 @@ * with some versions of clang. See http://llvm.org/bugs/show_bug.cgi?id=21499 * for details. */ -#define WT_ATOMIC_CAS(ptr, oldval, newval) \ - (__sync_val_compare_and_swap(ptr, oldval, newval) == oldval) +#define WT_ATOMIC_CAS(ptr, old, new) \ + (__sync_val_compare_and_swap(ptr, old, new) == (old)) #else -#define WT_ATOMIC_CAS(ptr, oldval, newval) \ - __sync_bool_compare_and_swap(ptr, oldval, newval) +#define WT_ATOMIC_CAS(ptr, old, new) \ + __sync_bool_compare_and_swap(ptr, old, new) #endif +#define WT_ATOMIC_CAS_FUNC(name, vp_arg, old_arg, new_arg) \ +static inline bool \ +__wt_atomic_cas##name(vp_arg, old_arg, new_arg) \ +{ \ + return (WT_ATOMIC_CAS(vp, old, new)); \ +} +WT_ATOMIC_CAS_FUNC(8, uint8_t *vp, uint8_t old, uint8_t new) +WT_ATOMIC_CAS_FUNC(16, uint16_t *vp, uint16_t old, uint16_t new) +WT_ATOMIC_CAS_FUNC(32, uint32_t *vp, uint32_t old, uint32_t new) +WT_ATOMIC_CAS_FUNC(v32, \ + volatile uint32_t *vp, volatile uint32_t old, volatile uint32_t new) +WT_ATOMIC_CAS_FUNC(i32, int32_t *vp, int32_t old, int32_t new) +WT_ATOMIC_CAS_FUNC(iv32, \ + volatile int32_t *vp, volatile int32_t old, volatile int32_t new) +WT_ATOMIC_CAS_FUNC(64, uint64_t *vp, uint64_t old, uint64_t new) +WT_ATOMIC_CAS_FUNC(v64, \ + volatile uint64_t *vp, volatile uint64_t old, volatile uint64_t new) +WT_ATOMIC_CAS_FUNC(i64, int64_t *vp, int64_t old, int64_t new) +WT_ATOMIC_CAS_FUNC(iv64, \ + volatile int64_t *vp, volatile int64_t old, volatile int64_t new) +WT_ATOMIC_CAS_FUNC(size, size_t *vp, size_t old, size_t new) -#define WT_ATOMIC_FUNC(name, ret, type) \ +/* + * __wt_atomic_cas_ptr -- + * Pointer compare and swap. + */ +static inline bool +__wt_atomic_cas_ptr(void *vp, void *old, void *new) +{ + return (WT_ATOMIC_CAS((void **)vp, old, new)); +} + +#define WT_ATOMIC_FUNC(name, ret, vp_arg, v_arg) \ static inline ret \ -__wt_atomic_add##name(type *vp, type v) \ +__wt_atomic_add##name(vp_arg, v_arg) \ { \ return (__sync_add_and_fetch(vp, v)); \ } \ static inline ret \ -__wt_atomic_fetch_add##name(type *vp, type v) \ +__wt_atomic_fetch_add##name(vp_arg, v_arg) \ { \ return (__sync_fetch_and_add(vp, v)); \ } \ static inline ret \ -__wt_atomic_store##name(type *vp, type v) \ +__wt_atomic_store##name(vp_arg, v_arg) \ { \ return (__sync_lock_test_and_set(vp, v)); \ } \ static inline ret \ -__wt_atomic_sub##name(type *vp, type v) \ +__wt_atomic_sub##name(vp_arg, v_arg) \ { \ return (__sync_sub_and_fetch(vp, v)); \ -} \ -static inline bool \ -__wt_atomic_cas##name(type *vp, type old, type new) \ -{ \ - return (WT_ATOMIC_CAS(vp, old, new)); \ -} - -WT_ATOMIC_FUNC(8, uint8_t, uint8_t) -WT_ATOMIC_FUNC(16, uint16_t, uint16_t) -WT_ATOMIC_FUNC(32, uint32_t, uint32_t) -WT_ATOMIC_FUNC(v32, uint32_t, volatile uint32_t) -WT_ATOMIC_FUNC(i32, int32_t, int32_t) -WT_ATOMIC_FUNC(iv32, int32_t, volatile int32_t) -WT_ATOMIC_FUNC(64, uint64_t, uint64_t) -WT_ATOMIC_FUNC(v64, uint64_t, volatile uint64_t) -WT_ATOMIC_FUNC(i64, int64_t, int64_t) -WT_ATOMIC_FUNC(iv64, int64_t, volatile int64_t) -WT_ATOMIC_FUNC(size, size_t, size_t) - -/* - * __wt_atomic_cas_ptr -- - * Pointer compare and swap. - */ -static inline bool -__wt_atomic_cas_ptr(void *vp, void *old, void *new) -{ - return (WT_ATOMIC_CAS((void **)vp, old, new)); } +WT_ATOMIC_FUNC(8, uint8_t, uint8_t *vp, uint8_t v) +WT_ATOMIC_FUNC(16, uint16_t, uint16_t *vp, uint16_t v) +WT_ATOMIC_FUNC(32, uint32_t, uint32_t *vp, uint32_t v) +WT_ATOMIC_FUNC(v32, uint32_t, volatile uint32_t *vp, volatile uint32_t v) +WT_ATOMIC_FUNC(i32, int32_t, int32_t *vp, int32_t v) +WT_ATOMIC_FUNC(iv32, int32_t, volatile int32_t *vp, volatile int32_t v) +WT_ATOMIC_FUNC(64, uint64_t, uint64_t *vp, uint64_t v) +WT_ATOMIC_FUNC(v64, uint64_t, volatile uint64_t *vp, volatile uint64_t v) +WT_ATOMIC_FUNC(i64, int64_t, int64_t *vp, int64_t v) +WT_ATOMIC_FUNC(iv64, int64_t, volatile int64_t *vp, volatile int64_t v) +WT_ATOMIC_FUNC(size, size_t, size_t *vp, size_t v) /* Compile read-write barrier */ #define WT_BARRIER() __asm__ volatile("" ::: "memory") |