summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_mutex.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2006-02-23 21:34:08 +0000
committerdeischen <deischen@FreeBSD.org>2006-02-23 21:34:08 +0000
commit4dd473489ef973f5d3a1b52dd87370ef00097810 (patch)
tree8d8078ef7abffc1a5ffc129a3fdf7c191a662be1 /lib/libpthread/thread/thr_mutex.c
parent2460d0002143524f8e136a911d7eece91b451d90 (diff)
downloadFreeBSD-src-4dd473489ef973f5d3a1b52dd87370ef00097810.zip
FreeBSD-src-4dd473489ef973f5d3a1b52dd87370ef00097810.tar.gz
Eliminate a race condition in timed waits (cv, mutex, and sleeps).
MFC Candidate. PR: 93592
Diffstat (limited to 'lib/libpthread/thread/thr_mutex.c')
-rw-r--r--lib/libpthread/thread/thr_mutex.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/lib/libpthread/thread/thr_mutex.c b/lib/libpthread/thread/thr_mutex.c
index e095ac5..0f56069 100644
--- a/lib/libpthread/thread/thr_mutex.c
+++ b/lib/libpthread/thread/thr_mutex.c
@@ -551,14 +551,6 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m,
/* Unlock the mutex structure: */
THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
} else {
- /* Set the wakeup time: */
- if (abstime) {
- curthread->wakeup_time.tv_sec =
- abstime->tv_sec;
- curthread->wakeup_time.tv_nsec =
- abstime->tv_nsec;
- }
-
/*
* Join the queue of threads waiting to lock
* the mutex and save a pointer to the mutex.
@@ -572,6 +564,14 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m,
* be able to safely set the state.
*/
THR_SCHED_LOCK(curthread, curthread);
+ /* Set the wakeup time: */
+ if (abstime) {
+ curthread->wakeup_time.tv_sec =
+ abstime->tv_sec;
+ curthread->wakeup_time.tv_nsec =
+ abstime->tv_nsec;
+ }
+
THR_SET_STATE(curthread, PS_MUTEX_WAIT);
THR_SCHED_UNLOCK(curthread, curthread);
@@ -633,14 +633,6 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m,
/* Unlock the mutex structure: */
THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
} else {
- /* Set the wakeup time: */
- if (abstime) {
- curthread->wakeup_time.tv_sec =
- abstime->tv_sec;
- curthread->wakeup_time.tv_nsec =
- abstime->tv_nsec;
- }
-
/*
* Join the queue of threads waiting to lock
* the mutex and save a pointer to the mutex.
@@ -659,6 +651,13 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m,
mutex_priority_adjust(curthread, *m);
THR_SCHED_LOCK(curthread, curthread);
+ /* Set the wakeup time: */
+ if (abstime) {
+ curthread->wakeup_time.tv_sec =
+ abstime->tv_sec;
+ curthread->wakeup_time.tv_nsec =
+ abstime->tv_nsec;
+ }
THR_SET_STATE(curthread, PS_MUTEX_WAIT);
THR_SCHED_UNLOCK(curthread, curthread);
@@ -730,14 +729,6 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m,
/* Unlock the mutex structure: */
THR_LOCK_RELEASE(curthread, &(*m)->m_lock);
} else {
- /* Set the wakeup time: */
- if (abstime) {
- curthread->wakeup_time.tv_sec =
- abstime->tv_sec;
- curthread->wakeup_time.tv_nsec =
- abstime->tv_nsec;
- }
-
/*
* Join the queue of threads waiting to lock
* the mutex and save a pointer to the mutex.
@@ -756,6 +747,13 @@ mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m,
*/
THR_SCHED_LOCK(curthread, curthread);
+ /* Set the wakeup time: */
+ if (abstime) {
+ curthread->wakeup_time.tv_sec =
+ abstime->tv_sec;
+ curthread->wakeup_time.tv_nsec =
+ abstime->tv_nsec;
+ }
THR_SET_STATE(curthread, PS_MUTEX_WAIT);
THR_SCHED_UNLOCK(curthread, curthread);
OpenPOWER on IntegriCloud