Postpone mutex initialization on FreeBSD.

Postpone mutex initialization on FreeBSD until after base allocation is
safe.
This commit is contained in:
Jason Evans
2012-04-03 08:47:07 -07:00
parent 48db6167e7
commit 633aaff967
3 changed files with 58 additions and 13 deletions

View File

@@ -651,6 +651,11 @@ malloc_init_hard(void)
return (true);
}
if (mutex_boot()) {
malloc_mutex_unlock(&init_lock);
return (true);
}
if (opt_narenas == 0) {
/*
* For SMP systems, create more than one arena per CPU by

View File

@@ -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);
}