From 92d3284ff8548c85b9b928f2615b96da4c4b2618 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Fri, 18 Mar 2011 18:15:37 -0700 Subject: [PATCH] Add atomic.[ch]. Add atomic.[ch], which should have been part of the previous commit. --- jemalloc/include/jemalloc/internal/atomic.h | 77 +++++++++++++++++++++ jemalloc/src/atomic.c | 2 + 2 files changed, 79 insertions(+) create mode 100644 jemalloc/include/jemalloc/internal/atomic.h create mode 100644 jemalloc/src/atomic.c diff --git a/jemalloc/include/jemalloc/internal/atomic.h b/jemalloc/include/jemalloc/internal/atomic.h new file mode 100644 index 00000000..43faeafc --- /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 00000000..77ee3131 --- /dev/null +++ b/jemalloc/src/atomic.c @@ -0,0 +1,2 @@ +#define JEMALLOC_ATOMIC_C_ +#include "jemalloc/internal/jemalloc_internal.h"