aboutsummaryrefslogtreecommitdiff
path: root/lib/libc_r
diff options
context:
space:
mode:
authorDmitrij Tejblum <dt@FreeBSD.org>1998-11-06 21:04:02 +0000
committerDmitrij Tejblum <dt@FreeBSD.org>1998-11-06 21:04:02 +0000
commit171a7528a8e1e6cd912ceadc1e70512aee9be495 (patch)
tree0db8175f008b05cb5d0207726b6e41d2676da6f4 /lib/libc_r
parented91f3baaf749489c75702de4ff8448c1d0f3051 (diff)
downloadsrc-171a7528a8e1e6cd912ceadc1e70512aee9be495.tar.gz
src-171a7528a8e1e6cd912ceadc1e70512aee9be495.zip
Don't call pthread_mutex_lock with _SPINLOCK held.
Made pthread_cond_wait() more similar to pthread_cond_timedwait(). PR: 8375
Notes
Notes: svn path=/head/; revision=40974
Diffstat (limited to 'lib/libc_r')
-rw-r--r--lib/libc_r/uthread/uthread_cond.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c
index fae12ebb68b5..e9b687d77e21 100644
--- a/lib/libc_r/uthread/uthread_cond.c
+++ b/lib/libc_r/uthread/uthread_cond.c
@@ -144,6 +144,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
switch ((*cond)->c_type) {
/* Fast condition variable: */
case COND_TYPE_FAST:
+ /* Wait forever: */
+ _thread_run->wakeup_time.tv_sec = -1;
+
/*
* Queue the running thread for the condition
* variable:
@@ -151,34 +154,39 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
_thread_queue_enq(&(*cond)->c_queue, _thread_run);
/* Unlock the mutex: */
- pthread_mutex_unlock(mutex);
-
- /* Wait forever: */
- _thread_run->wakeup_time.tv_sec = -1;
-
- /* Unlock the condition variable structure: */
- _SPINUNLOCK(&(*cond)->lock);
+ if ((rval = pthread_mutex_unlock(mutex)) != 0) {
+ /*
+ * Cannot unlock the mutex, so remove the
+ * running thread from the condition
+ * variable queue:
+ */
+ _thread_queue_deq(&(*cond)->c_queue);
- /* Schedule the next thread: */
- _thread_kern_sched_state(PS_COND_WAIT,
- __FILE__, __LINE__);
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
+ } else {
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
- /* Lock the condition variable structure: */
- _SPINLOCK(&(*cond)->lock);
+ /* Schedule the next thread: */
+ _thread_kern_sched_state(PS_COND_WAIT,
+ __FILE__, __LINE__);
- /* Lock the mutex: */
- rval = pthread_mutex_lock(mutex);
+ /* Lock the mutex: */
+ rval = pthread_mutex_lock(mutex);
+ }
break;
/* Trap invalid condition variable types: */
default:
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
+
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
- /* Unlock the condition variable structure: */
- _SPINUNLOCK(&(*cond)->lock);
}
/* Return the completion status: */
@@ -229,6 +237,9 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
* variable queue:
*/
_thread_queue_deq(&(*cond)->c_queue);
+
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
} else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
@@ -237,9 +248,6 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
_thread_kern_sched_state(PS_COND_WAIT,
__FILE__, __LINE__);
- /* Lock the condition variable structure: */
- _SPINLOCK(&(*cond)->lock);
-
/* Lock the mutex: */
if ((rval = pthread_mutex_lock(mutex)) != 0) {
}
@@ -253,13 +261,14 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Trap invalid condition variable types: */
default:
+ /* Unlock the condition variable structure: */
+ _SPINUNLOCK(&(*cond)->lock);
+
/* Return an invalid argument error: */
rval = EINVAL;
break;
}
- /* Unlock the condition variable structure: */
- _SPINUNLOCK(&(*cond)->lock);
}
/* Return the completion status: */