aboutsummaryrefslogtreecommitdiffstats
path: root/src/mutex.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2012-02-02 22:04:57 -0800
committerJason Evans <jasone@canonware.com>2012-02-02 23:09:53 -0800
commit41b6afb834b1f5250223678c52bd4f013d4234f6 (patch)
tree8900a100c2a98c3cf867755722a5dcdbfe7dac5e /src/mutex.c
parent6da5418ded9170b087c35960e0010006430117c1 (diff)
downloadplatform_external_jemalloc_new-41b6afb834b1f5250223678c52bd4f013d4234f6.tar.gz
platform_external_jemalloc_new-41b6afb834b1f5250223678c52bd4f013d4234f6.tar.bz2
platform_external_jemalloc_new-41b6afb834b1f5250223678c52bd4f013d4234f6.zip
Port to FreeBSD.
Use FreeBSD-specific functions (_pthread_mutex_init_calloc_cb(), _malloc_{pre,post}fork()) to avoid bootstrapping issues due to allocation in libc and libthr. Add malloc_strtoumax() and use it instead of strtoul(). Disable validation code in malloc_vsnprintf() and malloc_strtoumax() until jemalloc is initialized. This is necessary because locale initialization causes allocation for both vsnprintf() and strtoumax(). Force the lazy-lock feature on in order to avoid pthread_self(), because it causes allocation. Use syscall(SYS_write, ...) rather than write(...), because libthr wraps write() and causes allocation. Without this workaround, it would not be possible to print error messages in malloc_conf_init() without substantially reworking bootstrapping. Fix choose_arena_hard() to look at how many threads are assigned to the candidate choice, rather than checking whether the arena is uninitialized. This bug potentially caused more arenas to be initialized than necessary.
Diffstat (limited to 'src/mutex.c')
-rw-r--r--src/mutex.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/mutex.c b/src/mutex.c
index 07d2a033..0b20bbf3 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@ -56,21 +56,25 @@ pthread_create(pthread_t *__restrict thread,
/******************************************************************************/
+#ifdef JEMALLOC_MUTEX_INIT_CB
+int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
+ void *(calloc_cb)(size_t, size_t));
+#endif
+
bool
malloc_mutex_init(malloc_mutex_t *mutex)
{
#ifdef JEMALLOC_OSSPIN
*mutex = 0;
+#elif (defined(JEMALLOC_MUTEX_INIT_CB))
+ if (_pthread_mutex_init_calloc_cb(mutex, base_calloc) != 0)
+ return (true);
#else
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0)
return (true);
-#ifdef PTHREAD_MUTEX_ADAPTIVE_NP
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
-#else
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
-#endif
+ pthread_mutexattr_settype(&attr, MALLOC_MUTEX_TYPE);
if (pthread_mutex_init(mutex, &attr) != 0) {
pthread_mutexattr_destroy(&attr);
return (true);
@@ -99,10 +103,14 @@ void
malloc_mutex_postfork_child(malloc_mutex_t *mutex)
{
+#ifdef JEMALLOC_MUTEX_INIT_CB
+ malloc_mutex_unlock(mutex);
+#else
if (malloc_mutex_init(mutex)) {
malloc_printf("<jemalloc>: Error re-initializing mutex in "
"child\n");
if (opt_abort)
abort();
}
+#endif
}