about summary refs log tree commit diff
path: root/malloc/thread-m.h
diff options
context:
space:
mode:
Diffstat (limited to 'malloc/thread-m.h')
-rw-r--r--malloc/thread-m.h37
1 files changed, 29 insertions, 8 deletions
diff --git a/malloc/thread-m.h b/malloc/thread-m.h
index 34fea0e7d4..49db784c52 100644
--- a/malloc/thread-m.h
+++ b/malloc/thread-m.h
@@ -35,21 +35,42 @@
 
 #ifdef PTHREAD_MUTEX_INITIALIZER
 
-/* mutex */
 __libc_lock_define (typedef, mutex_t)
 
-/* Even if not linking with libpthread, ensure usability of mutex as
-   an `in use' flag, see also the NO_THREADS case below.  Assume
-   pthread_mutex_t is at least one int wide.  */
+#if defined(LLL_LOCK_INITIALIZER) && !defined(NOT_IN_libc)
+
+/* Assume NPTL.  */
+
+#define mutex_init(m)		__libc_lock_init (*(m))
+#define mutex_lock(m)		__libc_lock_lock (*(m))
+#define mutex_trylock(m)	__libc_lock_trylock (*(m))
+#define mutex_unlock(m)		__libc_lock_unlock (*(m))
+
+#elif defined(__libc_maybe_call2)
 
 #define mutex_init(m)		\
-  __libc_lock_init (*m)
+  __libc_maybe_call2 (pthread_mutex_init, (m, NULL), (*(int *)(m) = 0))
 #define mutex_lock(m)		\
-  __libc_lock_lock (*m)
+  __libc_maybe_call2 (pthread_mutex_lock, (m), ((*(int *)(m) = 1), 0))
 #define mutex_trylock(m)	\
-  __libc_lock_trylock (*m)
+  __libc_maybe_call2 (pthread_mutex_trylock, (m), \
+		      (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
 #define mutex_unlock(m)		\
-  __libc_lock_unlock (*m)
+  __libc_maybe_call2 (pthread_mutex_unlock, (m), (*(int *)(m) = 0))
+
+#else
+
+#define mutex_init(m)		\
+  __libc_maybe_call (__pthread_mutex_init, (m, NULL), (*(int *)(m) = 0))
+#define mutex_lock(m)		\
+  __libc_maybe_call (__pthread_mutex_lock, (m), ((*(int *)(m) = 1), 0))
+#define mutex_trylock(m)	\
+  __libc_maybe_call (__pthread_mutex_trylock, (m), \
+		     (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
+#define mutex_unlock(m)		\
+  __libc_maybe_call (__pthread_mutex_unlock, (m), (*(int *)(m) = 0))
+
+#endif
 
 #define thread_atfork(prepare, parent, child) \
    (__pthread_atfork != NULL ? __pthread_atfork(prepare, parent, child) : 0)