diff options
author | Jason Evans <je@fb.com> | 2011-03-19 02:30:18 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2011-03-19 02:30:18 (GMT) |
commit | 893a0ed7c8c11962524ba6f2adeb304d038be2a9 (patch) | |
tree | f3250f735a97587da8ca61f0208f07bc28cd65fe /jemalloc/src | |
parent | 763baa6cfcc8a9df9d3b7f676b2193ac7cd5ef51 (diff) | |
download | jemalloc-893a0ed7c8c11962524ba6f2adeb304d038be2a9.zip jemalloc-893a0ed7c8c11962524ba6f2adeb304d038be2a9.tar.gz jemalloc-893a0ed7c8c11962524ba6f2adeb304d038be2a9.tar.bz2 |
Use OSSpinLock*() for locking on OS X.
pthread_mutex_lock() can call malloc() on OS X (!!!), which causes
deadlock. Work around this by using spinlocks that are built of more
primitive stuff.
Diffstat (limited to 'jemalloc/src')
-rw-r--r-- | jemalloc/src/jemalloc.c | 8 | ||||
-rw-r--r-- | jemalloc/src/mutex.c | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c index 0efafde..dccce6b 100644 --- a/jemalloc/src/jemalloc.c +++ b/jemalloc/src/jemalloc.c @@ -28,7 +28,13 @@ static bool malloc_initialized = false; static pthread_t malloc_initializer = (unsigned long)0; /* Used to avoid initialization races. */ -static malloc_mutex_t init_lock = MALLOC_MUTEX_INITIALIZER; +static malloc_mutex_t init_lock = +#ifdef JEMALLOC_OSSPIN + 0 +#else + MALLOC_MUTEX_INITIALIZER +#endif + ; #ifdef DYNAMIC_PAGE_SHIFT size_t pagesize; diff --git a/jemalloc/src/mutex.c b/jemalloc/src/mutex.c index 3ecb18a..ca89ef1 100644 --- a/jemalloc/src/mutex.c +++ b/jemalloc/src/mutex.c @@ -55,6 +55,9 @@ pthread_create(pthread_t *__restrict thread, bool malloc_mutex_init(malloc_mutex_t *mutex) { +#ifdef JEMALLOC_OSSPIN + *mutex = 0; +#else pthread_mutexattr_t attr; if (pthread_mutexattr_init(&attr) != 0) @@ -70,6 +73,7 @@ malloc_mutex_init(malloc_mutex_t *mutex) } pthread_mutexattr_destroy(&attr); +#endif return (false); } @@ -77,8 +81,10 @@ void malloc_mutex_destroy(malloc_mutex_t *mutex) { +#ifndef JEMALLOC_OSSPIN if (pthread_mutex_destroy(mutex) != 0) { malloc_write("<jemalloc>: Error in pthread_mutex_destroy()\n"); abort(); } +#endif } |