diff options
author | Jason Evans <je@fb.com> | 2011-03-19 01:15:37 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2011-03-19 01:15:37 (GMT) |
commit | 92d3284ff8548c85b9b928f2615b96da4c4b2618 (patch) | |
tree | b2afacf3d7802964066ed79026961701f5c49ad8 /jemalloc | |
parent | 0657f12acd43eb2082a71230341449eca648bc9b (diff) | |
download | jemalloc-92d3284ff8548c85b9b928f2615b96da4c4b2618.zip jemalloc-92d3284ff8548c85b9b928f2615b96da4c4b2618.tar.gz jemalloc-92d3284ff8548c85b9b928f2615b96da4c4b2618.tar.bz2 |
Add atomic.[ch].
Add atomic.[ch], which should have been part of the previous commit.
Diffstat (limited to 'jemalloc')
-rw-r--r-- | jemalloc/include/jemalloc/internal/atomic.h | 77 | ||||
-rw-r--r-- | jemalloc/src/atomic.c | 2 |
2 files changed, 79 insertions, 0 deletions
diff --git a/jemalloc/include/jemalloc/internal/atomic.h b/jemalloc/include/jemalloc/internal/atomic.h new file mode 100644 index 0000000..43faeaf --- /dev/null +++ b/jemalloc/include/jemalloc/internal/atomic.h @@ -0,0 +1,77 @@ +/******************************************************************************/ +#ifdef JEMALLOC_H_TYPES + +#endif /* JEMALLOC_H_TYPES */ +/******************************************************************************/ +#ifdef JEMALLOC_H_STRUCTS + +#endif /* JEMALLOC_H_STRUCTS */ +/******************************************************************************/ +#ifdef JEMALLOC_H_EXTERNS + +#define atomic_read_uint64(p) atomic_add_uint64(p, 0) +#define atomic_read_uint32(p) atomic_add_uint32(p, 0) + +#if (LG_SIZEOF_PTR == 3) +# define atomic_read_z(p) atomic_add_uint64(p, 0) +# define atomic_add_z(p, x) atomic_add_uint64(p, x) +# define atomic_sub_z(p, x) atomic_sub_uint64(p, x) +#elif (LG_SIZEOF_PTR == 2) +# define atomic_read_z(p) atomic_add_uint32(p, 0) +# define atomic_add_z(p, x) atomic_add_uint32(p, x) +# define atomic_sub_z(p, x) atomic_sub_uint32(p, x) +#endif + +#endif /* JEMALLOC_H_EXTERNS */ +/******************************************************************************/ +#ifdef JEMALLOC_H_INLINES + +#ifndef JEMALLOC_ENABLE_INLINE +uint64_t atomic_add_uint64(uint64_t *p, uint64_t x); +uint64_t atomic_sub_uint64(uint64_t *p, uint64_t x); +uint32_t atomic_add_uint32(uint32_t *p, uint32_t x); +uint32_t atomic_sub_uint32(uint32_t *p, uint32_t x); +#endif + +#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_ATOMIC_C_)) +/* 64-bit operations. */ +#ifdef __GCC_HAVE_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 +# error "Missing implementation for 64-bit atomic operations" +#endif + +/* 32-bit operations. */ +#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 +JEMALLOC_INLINE uint32_t +atomic_add_uint32(uint32_t *p, uint32_t x) +{ + + return (__sync_add_and_fetch(p, x)); +} + +JEMALLOC_INLINE uint32_t +atomic_sub_uint32(uint32_t *p, uint32_t x) +{ + + return (__sync_sub_and_fetch(p, x)); +} +#else +# error "Missing implementation for 32-bit atomic operations" +#endif +#endif + +#endif /* JEMALLOC_H_INLINES */ +/******************************************************************************/ diff --git a/jemalloc/src/atomic.c b/jemalloc/src/atomic.c new file mode 100644 index 0000000..77ee313 --- /dev/null +++ b/jemalloc/src/atomic.c @@ -0,0 +1,2 @@ +#define JEMALLOC_ATOMIC_C_ +#include "jemalloc/internal/jemalloc_internal.h" |