summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authorjb <jb@FreeBSD.org>1997-04-11 22:38:22 +0000
committerjb <jb@FreeBSD.org>1997-04-11 22:38:22 +0000
commit0b77d30d2b211d5c0e9c1609cdf6529d8c5391f6 (patch)
tree99c8ed33d1c734b0992caeeb8a31437e80f3387c /lib/libpthread
parent60f2e3c5de0c6c75c96713e811e81a14bc0d62dc (diff)
downloadFreeBSD-src-0b77d30d2b211d5c0e9c1609cdf6529d8c5391f6.zip
FreeBSD-src-0b77d30d2b211d5c0e9c1609cdf6529d8c5391f6.tar.gz
Set wakeup time in pthread_cond_wait() to `forever' (-1) to prevent
calling thread from being rescheduled based on an unspecified wakeup time. Bug/fix pointed out by Alexandre Fenyo <fenyo@email.enst.fr>.
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/thread/thr_cond.c65
1 files changed, 41 insertions, 24 deletions
diff --git a/lib/libpthread/thread/thr_cond.c b/lib/libpthread/thread/thr_cond.c
index 2fe4532..09ebb4e 100644
--- a/lib/libpthread/thread/thr_cond.c
+++ b/lib/libpthread/thread/thr_cond.c
@@ -48,8 +48,8 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
rval = -1;
} else {
/*
- * Check if a pointer to a condition variable attribute structure was
- * passed by the caller:
+ * Check if a pointer to a condition variable attribute
+ * structure was passed by the caller:
*/
if (cond_attr != NULL && *cond_attr != NULL) {
/* Default to a fast condition variable: */
@@ -61,12 +61,12 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
/* Process according to condition variable type: */
switch (type) {
- /* Fast condition variable: */
+ /* Fast condition variable: */
case COND_TYPE_FAST:
/* Nothing to do here. */
break;
- /* Trap invalid condition variable types: */
+ /* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
@@ -76,7 +76,8 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
/* Check for no errors: */
if (rval == 0) {
- if ((pcond = (pthread_cond_t) malloc(sizeof(struct pthread_cond))) == NULL) {
+ if ((pcond = (pthread_cond_t)
+ malloc(sizeof(struct pthread_cond))) == NULL) {
errno = ENOMEM;
rval = -1;
} else {
@@ -106,12 +107,12 @@ pthread_cond_destroy(pthread_cond_t * cond)
} else {
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
- /* Fast condition variable: */
+ /* Fast condition variable: */
case COND_TYPE_FAST:
/* Nothing to do here. */
break;
- /* Trap invalid condition variable types: */
+ /* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
@@ -147,16 +148,23 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
- /* Fast condition variable: */
+ /* Fast condition variable: */
case COND_TYPE_FAST:
- /* Queue the running thread for the condition variable: */
- _thread_queue_enq(&(*cond)->c_queue, _thread_run);
+ /*
+ * Queue the running thread for the condition
+ * variable:
+ */
+ _thread_queue_enq(&(*cond)->c_queue, _thread_run);
/* Unlock the mutex: */
pthread_mutex_unlock(mutex);
+ /* Wait forever: */
+ _thread_run->wakeup_time.tv_sec = -1;
+
/* Schedule the next thread: */
- _thread_kern_sched_state(PS_COND_WAIT, __FILE__, __LINE__);
+ _thread_kern_sched_state(PS_COND_WAIT,
+ __FILE__, __LINE__);
/* Block signals: */
_thread_kern_sig_block(NULL);
@@ -165,7 +173,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
rval = pthread_mutex_lock(mutex);
break;
- /* Trap invalid condition variable types: */
+ /* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
@@ -197,7 +205,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
- /* Fast condition variable: */
+ /* Fast condition variable: */
case COND_TYPE_FAST:
/* Set the wakeup time: */
_thread_run->wakeup_time.tv_sec = abstime->tv_sec;
@@ -206,19 +214,24 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Reset the timeout flag: */
_thread_run->timeout = 0;
- /* Queue the running thread for the condition variable: */
+ /*
+ * Queue the running thread for the condition
+ * variable:
+ */
_thread_queue_enq(&(*cond)->c_queue, _thread_run);
/* Unlock the mutex: */
if ((rval = pthread_mutex_unlock(mutex)) != 0) {
/*
- * Cannot unlock the mutex, so remove the running
- * thread from the condition variable queue:
+ * Cannot unlock the mutex, so remove the
+ * running thread from the condition
+ * variable queue:
*/
_thread_queue_deq(&(*cond)->c_queue);
} else {
/* Schedule the next thread: */
- _thread_kern_sched_state(PS_COND_WAIT, __FILE__, __LINE__);
+ _thread_kern_sched_state(PS_COND_WAIT,
+ __FILE__, __LINE__);
/* Block signals: */
_thread_kern_sig_block(NULL);
@@ -235,7 +248,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
}
break;
- /* Trap invalid condition variable types: */
+ /* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
@@ -267,7 +280,7 @@ pthread_cond_signal(pthread_cond_t * cond)
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
- /* Fast condition variable: */
+ /* Fast condition variable: */
case COND_TYPE_FAST:
/* Bring the next thread off the condition queue: */
if ((pthread = _thread_queue_deq(&(*cond)->c_queue)) != NULL) {
@@ -276,7 +289,7 @@ pthread_cond_signal(pthread_cond_t * cond)
}
break;
- /* Trap invalid condition variable types: */
+ /* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
@@ -304,16 +317,20 @@ pthread_cond_broadcast(pthread_cond_t * cond)
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
- /* Fast condition variable: */
+ /* Fast condition variable: */
case COND_TYPE_FAST:
- /* Enter a loop to bring all threads off the condition queue: */
- while ((pthread = _thread_queue_deq(&(*cond)->c_queue)) != NULL) {
+ /*
+ * Enter a loop to bring all threads off the
+ * condition queue:
+ */
+ while ((pthread =
+ _thread_queue_deq(&(*cond)->c_queue)) != NULL) {
/* Allow the thread to run: */
PTHREAD_NEW_STATE(pthread,PS_RUNNING);
}
break;
- /* Trap invalid condition variable types: */
+ /* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
OpenPOWER on IntegriCloud