aboutsummaryrefslogtreecommitdiff
path: root/lib/libkse/thread/thr_mutex.c
diff options
context:
space:
mode:
authorJohn Birrell <jb@FreeBSD.org>1999-05-23 10:55:33 +0000
committerJohn Birrell <jb@FreeBSD.org>1999-05-23 10:55:33 +0000
commiteb9dc34d8b2b38586a59ff6c59674d9cd672b7d8 (patch)
tree2fe6e193ddad102e2e7fa9b046a21b09325219b4 /lib/libkse/thread/thr_mutex.c
parentd47066829aa3b417818cef2c14ee1b7c96c6b566 (diff)
downloadsrc-eb9dc34d8b2b38586a59ff6c59674d9cd672b7d8.tar.gz
src-eb9dc34d8b2b38586a59ff6c59674d9cd672b7d8.zip
Fix a problem with static initialisation of mutexes and condition
variables. Submitted by: Dan Eischen <eischen@vigrid.com>
Notes
Notes: svn path=/head/; revision=47424
Diffstat (limited to 'lib/libkse/thread/thr_mutex.c')
-rw-r--r--lib/libkse/thread/thr_mutex.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c
index 0103a6cd663a..fa9c8cfe15db 100644
--- a/lib/libkse/thread/thr_mutex.c
+++ b/lib/libkse/thread/thr_mutex.c
@@ -222,6 +222,15 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
*/
else if (*mutex != NULL || (ret = init_static(mutex)) == 0) {
/*
+ * If the mutex was statically allocated, properly
+ * initialize the tail queue.
+ */
+ if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) {
+ TAILQ_INIT(&(*mutex)->m_queue);
+ (*mutex)->m_flags |= MUTEX_FLAGS_INITED;
+ }
+
+ /*
* Guard against being preempted by a scheduling signal.
* To support priority inheritence mutexes, we need to
* maintain lists of mutex ownerships for each thread as
@@ -352,6 +361,15 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/
else if (*mutex != NULL || (ret = init_static(mutex)) == 0) {
/*
+ * If the mutex was statically allocated, properly
+ * initialize the tail queue.
+ */
+ if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) {
+ TAILQ_INIT(&(*mutex)->m_queue);
+ (*mutex)->m_flags |= MUTEX_FLAGS_INITED;
+ }
+
+ /*
* Guard against being preempted by a scheduling signal.
* To support priority inheritence mutexes, we need to
* maintain lists of mutex ownerships for each thread as