summaryrefslogtreecommitdiffstats
path: root/lib/libkse/thread/thr_mutex.c
diff options
context:
space:
mode:
authorjasone <jasone@FreeBSD.org>2007-11-27 03:16:44 +0000
committerjasone <jasone@FreeBSD.org>2007-11-27 03:16:44 +0000
commit21bb948195adb6636c33738cab39bb89cac41bc7 (patch)
treebc0c2019e6f4f8b5aa0d67d7e3517c626797bb0e /lib/libkse/thread/thr_mutex.c
parent2dd595aefe6b80476344fe4fc8b7934db055aaa2 (diff)
downloadFreeBSD-src-21bb948195adb6636c33738cab39bb89cac41bc7.zip
FreeBSD-src-21bb948195adb6636c33738cab39bb89cac41bc7.tar.gz
Add _pthread_mutex_init_calloc_cb() to libthr and libkse, so that malloc(3)
(part of libc) can use pthreads mutexes without causing infinite recursion during initialization.
Diffstat (limited to 'lib/libkse/thread/thr_mutex.c')
-rw-r--r--lib/libkse/thread/thr_mutex.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c
index 264e01e..d8bf498 100644
--- a/lib/libkse/thread/thr_mutex.c
+++ b/lib/libkse/thread/thr_mutex.c
@@ -115,11 +115,9 @@ __weak_reference(__pthread_mutex_trylock, pthread_mutex_trylock);
__weak_reference(_pthread_mutex_destroy, pthread_mutex_destroy);
__weak_reference(_pthread_mutex_unlock, pthread_mutex_unlock);
-
-
-int
-__pthread_mutex_init(pthread_mutex_t *mutex,
- const pthread_mutexattr_t *mutex_attr)
+static int
+thr_mutex_init(pthread_mutex_t *mutex,
+ const pthread_mutexattr_t *mutex_attr, void *(calloc_cb)(size_t, size_t))
{
struct pthread_mutex *pmutex;
enum pthread_mutextype type;
@@ -163,10 +161,10 @@ __pthread_mutex_init(pthread_mutex_t *mutex,
/* Check no errors so far: */
if (ret == 0) {
if ((pmutex = (pthread_mutex_t)
- malloc(sizeof(struct pthread_mutex))) == NULL)
+ calloc_cb(1, sizeof(struct pthread_mutex))) == NULL)
ret = ENOMEM;
else if (_lock_init(&pmutex->m_lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0) {
+ _thr_lock_wait, _thr_lock_wakeup, calloc_cb) != 0) {
free(pmutex);
*mutex = NULL;
ret = ENOMEM;
@@ -222,6 +220,14 @@ __pthread_mutex_init(pthread_mutex_t *mutex,
}
int
+__pthread_mutex_init(pthread_mutex_t *mutex,
+ const pthread_mutexattr_t *mutex_attr)
+{
+
+ return (thr_mutex_init(mutex, mutex_attr, calloc));
+}
+
+int
_pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *mutex_attr)
{
@@ -237,6 +243,22 @@ _pthread_mutex_init(pthread_mutex_t *mutex,
}
}
+/* This function is used internally by malloc. */
+int
+_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
+ void *(calloc_cb)(size_t, size_t))
+{
+ static const struct pthread_mutex_attr attr = {
+ .m_type = PTHREAD_MUTEX_NORMAL,
+ .m_protocol = PTHREAD_PRIO_NONE,
+ .m_ceiling = 0,
+ .m_flags = 0
+ };
+
+ return (thr_mutex_init(mutex, (pthread_mutexattr_t *)&attr,
+ calloc_cb));
+}
+
void
_thr_mutex_reinit(pthread_mutex_t *mutex)
{
OpenPOWER on IntegriCloud