diff options
author | Jason Evans <jasone@canonware.com> | 2012-04-03 15:47:07 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2012-04-04 02:25:30 (GMT) |
commit | 633aaff96787db82c06d35baf012de197a1a1902 (patch) | |
tree | e8b82632d7ab3ad8439dfecb418e34df4b0495b2 /src/mutex.c | |
parent | 48db6167e7bddd26660d7eb3a4ac173284b79948 (diff) | |
download | jemalloc-633aaff96787db82c06d35baf012de197a1a1902.zip jemalloc-633aaff96787db82c06d35baf012de197a1a1902.tar.gz jemalloc-633aaff96787db82c06d35baf012de197a1a1902.tar.bz2 |
Postpone mutex initialization on FreeBSD.
Postpone mutex initialization on FreeBSD until after base allocation is
safe.
Diffstat (limited to 'src/mutex.c')
-rw-r--r-- | src/mutex.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/mutex.c b/src/mutex.c index 0b20bbf..4b8ce57 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -11,6 +11,10 @@ #ifdef JEMALLOC_LAZY_LOCK bool isthreaded = false; #endif +#ifdef JEMALLOC_MUTEX_INIT_CB +static bool postpone_init = true; +static malloc_mutex_t *postponed_mutexes = NULL; +#endif #ifdef JEMALLOC_LAZY_LOCK static void pthread_create_once(void); @@ -65,17 +69,23 @@ bool malloc_mutex_init(malloc_mutex_t *mutex) { #ifdef JEMALLOC_OSSPIN - *mutex = 0; + mutex->lock = 0; #elif (defined(JEMALLOC_MUTEX_INIT_CB)) - if (_pthread_mutex_init_calloc_cb(mutex, base_calloc) != 0) - return (true); + if (postpone_init) { + mutex->postponed_next = postponed_mutexes; + postponed_mutexes = mutex; + } else { + if (_pthread_mutex_init_calloc_cb(&mutex->lock, base_calloc) != + 0) + return (true); + } #else pthread_mutexattr_t attr; if (pthread_mutexattr_init(&attr) != 0) return (true); pthread_mutexattr_settype(&attr, MALLOC_MUTEX_TYPE); - if (pthread_mutex_init(mutex, &attr) != 0) { + if (pthread_mutex_init(&mutex->lock, &attr) != 0) { pthread_mutexattr_destroy(&attr); return (true); } @@ -114,3 +124,19 @@ malloc_mutex_postfork_child(malloc_mutex_t *mutex) } #endif } + +bool +mutex_boot(void) +{ + +#ifdef JEMALLOC_MUTEX_INIT_CB + postpone_init = false; + while (postponed_mutexes != NULL) { + if (_pthread_mutex_init_calloc_cb(&postponed_mutexes->lock, + base_calloc) != 0) + return (true); + postponed_mutexes = postponed_mutexes->postponed_next; + } +#endif + return (false); +} |