summaryrefslogtreecommitdiff
path: root/thread-utils.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-06-16 16:21:06 -0700
committerJunio C Hamano <gitster@pobox.com>2010-06-16 16:21:06 -0700
commit5c1eba5e312838774afe44bb52885f3cd7e4ac7a (patch)
treedccf68a10a7a8666720202bcc9ece2ef3138a2b1 /thread-utils.c
parent419ff2c575b96555dedac8c736025acfca9f982f (diff)
parent937491944292fa3303b565b9bd8914c6b644ab13 (diff)
downloadgit-5c1eba5e312838774afe44bb52885f3cd7e4ac7a.tar.gz
Merge branch 'np/malloc-threading' into maint
* np/malloc-threading: Thread-safe xmalloc and xrealloc needs a recursive mutex Make xmalloc and xrealloc thread-safe
Diffstat (limited to 'thread-utils.c')
-rw-r--r--thread-utils.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/thread-utils.c b/thread-utils.c
index 4f9c829c2d..589f838f82 100644
--- a/thread-utils.c
+++ b/thread-utils.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include <pthread.h>
#if defined(hpux) || defined(__hpux) || defined(_hpux)
# include <sys/pstat.h>
@@ -43,3 +44,18 @@ int online_cpus(void)
return 1;
}
+
+int init_recursive_mutex(pthread_mutex_t *m)
+{
+ pthread_mutexattr_t a;
+ int ret;
+
+ ret = pthread_mutexattr_init(&a);
+ if (!ret) {
+ ret = pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE);
+ if (!ret)
+ ret = pthread_mutex_init(m, &a);
+ pthread_mutexattr_destroy(&a);
+ }
+ return ret;
+}