diff options
author | Jason Evans <je@fb.com> | 2011-03-19 02:10:31 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2011-03-19 02:10:31 (GMT) |
commit | 763baa6cfcc8a9df9d3b7f676b2193ac7cd5ef51 (patch) | |
tree | a7bbdaca10c8111dfb7a39d7ec97ec1c8132b415 /jemalloc | |
parent | 9a8fc41bb9752129510f3387f5c20cb798ff6b1a (diff) | |
download | jemalloc-763baa6cfcc8a9df9d3b7f676b2193ac7cd5ef51.zip jemalloc-763baa6cfcc8a9df9d3b7f676b2193ac7cd5ef51.tar.gz jemalloc-763baa6cfcc8a9df9d3b7f676b2193ac7cd5ef51.tar.bz2 |
Add atomic operation support for OS X.
Diffstat (limited to 'jemalloc')
-rw-r--r-- | jemalloc/configure.ac | 22 | ||||
-rw-r--r-- | jemalloc/include/jemalloc/internal/atomic.h | 28 | ||||
-rw-r--r-- | jemalloc/include/jemalloc/internal/jemalloc_internal.h.in | 4 | ||||
-rw-r--r-- | jemalloc/include/jemalloc/jemalloc_defs.h.in | 6 |
4 files changed, 60 insertions, 0 deletions
diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac index dc77d75..c40d22f 100644 --- a/jemalloc/configure.ac +++ b/jemalloc/configure.ac @@ -771,6 +771,28 @@ AC_CHECK_FUNC([ffsl], [], [AC_MSG_ERROR([Cannot build without ffsl(3)])]) dnl ============================================================================ +dnl Check for atomic(3) operations as provided on Darwin. + +JE_COMPILABLE([Darwin OSAtomic*()], [ +#include <libkern/OSAtomic.h> +#include <inttypes.h> +], [ + { + int32_t x32 = 0; + volatile int32_t *x32p = &x32; + OSAtomicAdd32(1, x32p); + } + { + int64_t x64 = 0; + volatile int64_t *x64p = &x64; + OSAtomicAdd64(1, x64p); + } +], [osatomic]) +if test "x${osatomic}" = "xyes" ; then + AC_DEFINE([JEMALLOC_OSATOMIC]) +fi + +dnl ============================================================================ dnl Check for allocator-related functions that should be wrapped. AC_CHECK_FUNC([memalign], diff --git a/jemalloc/include/jemalloc/internal/atomic.h b/jemalloc/include/jemalloc/internal/atomic.h index 43faeaf..089affa 100644 --- a/jemalloc/include/jemalloc/internal/atomic.h +++ b/jemalloc/include/jemalloc/internal/atomic.h @@ -49,6 +49,20 @@ atomic_sub_uint64(uint64_t *p, uint64_t x) return (__sync_sub_and_fetch(p, x)); } +#elif (defined(JEMALLOC_OSATOMIC)) +JEMALLOC_INLINE uint64_t +atomic_add_uint64(uint64_t *p, uint64_t x) +{ + + return (OSAtomicAdd64((int64_t)x, (int64_t *)p)); +} + +JEMALLOC_INLINE uint64_t +atomic_sub_uint64(uint64_t *p, uint64_t x) +{ + + return (OSAtomicAdd64(-((int64_t)x), (int64_t *)p)); +} #else # error "Missing implementation for 64-bit atomic operations" #endif @@ -68,6 +82,20 @@ atomic_sub_uint32(uint32_t *p, uint32_t x) return (__sync_sub_and_fetch(p, x)); } +#elif (defined(JEMALLOC_OSATOMIC)) +JEMALLOC_INLINE uint32_t +atomic_add_uint32(uint32_t *p, uint32_t x) +{ + + return (OSAtomicAdd32((int32_t)x, (int32_t *)p)); +} + +JEMALLOC_INLINE uint32_t +atomic_sub_uint32(uint32_t *p, uint32_t x) +{ + + return (OSAtomicAdd32(-((int32_t)x), (int32_t *)p)); +} #else # error "Missing implementation for 32-bit atomic operations" #endif diff --git a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in index 90cd604..f660bc8 100644 --- a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in +++ b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in @@ -33,6 +33,10 @@ #define JEMALLOC_MANGLE #include "../jemalloc@install_suffix@.h" +#ifdef JEMALLOC_OSATOMIC +#include <libkern/OSAtomic.h> +#endif + #ifdef JEMALLOC_ZONE #include <mach/mach_error.h> #include <mach/mach_init.h> diff --git a/jemalloc/include/jemalloc/jemalloc_defs.h.in b/jemalloc/include/jemalloc/jemalloc_defs.h.in index d669841..c08c5a2 100644 --- a/jemalloc/include/jemalloc/jemalloc_defs.h.in +++ b/jemalloc/include/jemalloc/jemalloc_defs.h.in @@ -24,6 +24,12 @@ */ #undef CPU_SPINWAIT +/* + * Defined if OSAtomic*() functions are available, as provided by Darwin, and + * documented in the atomic(3) manual page. + */ +#undef JEMALLOC_OSATOMIC + /* Defined if __attribute__((...)) syntax is supported. */ #undef JEMALLOC_HAVE_ATTR #ifdef JEMALLOC_HAVE_ATTR |