diff options
author | Mike Hommey <mh@glandium.org> | 2012-03-26 17:03:41 +0200 |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2012-03-26 11:51:13 -0700 |
commit | c1e567bda042d94159026b96e7a77683606037fa (patch) | |
tree | e0df931a3921136fcd552fb9c3d23dcf6e55968d /include/jemalloc/internal/atomic.h | |
parent | 1e6138c88c7f3bb1f0e8fb785080ac5abc24210c (diff) | |
download | jemalloc-c1e567bda042d94159026b96e7a77683606037fa.tar.gz |
Use __sync_add_and_fetch and __sync_sub_and_fetch when they are available
These functions may be available as inlines or as libgcc functions. In the
former case, a __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macro is defined. But we
still want to use these functions in the latter case, when we don't have
our own implementation.
Diffstat (limited to 'include/jemalloc/internal/atomic.h')
-rw-r--r-- | include/jemalloc/internal/atomic.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/include/jemalloc/internal/atomic.h b/include/jemalloc/internal/atomic.h index 7a9cb61..d8f6ca5 100644 --- a/include/jemalloc/internal/atomic.h +++ b/include/jemalloc/internal/atomic.h @@ -87,6 +87,20 @@ atomic_sub_uint64(uint64_t *p, uint64_t x) return (x); } +#elif (defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_8)) +JEMALLOC_INLINE uint64_t +atomic_add_uint64(uint64_t *p, uint64_t x) +{ + + return (__sync_add_and_fetch(p, x)); +} + +JEMALLOC_INLINE uint64_t +atomic_sub_uint64(uint64_t *p, uint64_t x) +{ + + return (__sync_sub_and_fetch(p, x)); +} #else # if (LG_SIZEOF_PTR == 3) # error "Missing implementation for 64-bit atomic operations" @@ -150,9 +164,7 @@ atomic_sub_uint32(uint32_t *p, uint32_t x) return (x); } -#elif (defined __SH4__ || defined __mips__) && (__GNUC__ > 4 || \ - (__GNUC__ == 4 && (__GNUC_MINOR__ > 1 || (__GNUC_MINOR__ == 1 && \ - __GNUC_PATCHLEVEL__ > 1)))) +#elif (defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4)) JEMALLOC_INLINE uint32_t atomic_add_uint32(uint32_t *p, uint32_t x) { |