summaryrefslogtreecommitdiff
path: root/condvar.c
diff options
context:
space:
mode:
authorrpj <rpj>1999-01-12 14:48:53 +0000
committerrpj <rpj>1999-01-12 14:48:53 +0000
commitbc374000d4dda28009ceb1f03a5514687be8904c (patch)
treeed0423713c55ec8c5fcd7ea801edbda62bef6ab7 /condvar.c
parent66f7d3aafbde9b4f628dcdc23c7f59b28d86760b (diff)
Wed Jan 13 09:34:52 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* build.bat: Delete old binaries before compiling/linking. Tue Jan 12 09:58:38 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * dll.c: The Microsoft compiler pragmas probably are more appropriately protected by _MSC_VER than by _WIN32. - Tor Lillqvist <tml@iki.fi>. * condvar.c (pthread_cond_timedwait): Fix function description comments. * pthread.h: Define ETIMEDOUT. This should be returned by pthread_cond_timedwait which is not implemented yet as of snapshot-1999-01-04-1305. It was implemented in the older version. The Microsoft compiler pragmas probably are more appropriately protected by _MSC_VER than by _WIN32. - Tor Lillqvist <tml@iki.fi>. * pthread.def: pthread_mutex_destroy was missing from the def file - Tor Lillqvist <tml@iki.fi>. * condvar.c (pthread_cond_broadcast): Ensure we only wait on threads if there were any waiting on the condition. I think pthread_cond_broadcast should do the WaitForSingleObject only if cv->waiters > 0? Otherwise it seems to hang, at least in the testg thread program from glib. - Tor Lillqvist <tml@iki.fi>. * semaphore.c (sem_post): Correct typo in comment. Mon Jan 11 20:33:19 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * pthread.h: Re-arrange conditional compile of pthread_cleanup-* macros. * cleanup.c (_pthread_push_cleanup): Provide conditional compile of cleanup->prev.
Diffstat (limited to 'condvar.c')
-rw-r--r--condvar.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/condvar.c b/condvar.c
index f9230c1..c4e846b 100644
--- a/condvar.c
+++ b/condvar.c
@@ -543,20 +543,37 @@ pthread_cond_timedwait (pthread_cond_t * cond,
* initial value of the semaphore is 'value'
*
* PARAMETERS
- * sem
- * pointer to an instance of sem_t
+ * cond
+ * pointer to an instance of pthread_cond_t
+ *
+ * mutex
+ * pointer to an instance of pthread_mutex_t
+ *
+ * abstime
+ * pointer to an instance of (const struct timespec)
*
*
* DESCRIPTION
- * This function initializes an unnamed semaphore. The
- * initial value of the semaphore is set to 'value'.
+ * This function waits on a condition variable either until
+ * awakened by a signal or broadcast; or until the time
+ * specified by abstime passes.
+ *
+ * NOTES:
+ * 1) The function must be called with 'mutex' LOCKED
+ * by the calling thread, or undefined behaviour
+ * will result.
+ *
+ * 2) This routine atomically releases 'mutex' and causes
+ * the calling thread to block on the condition variable.
+ * The blocked thread may be awakened by
+ * pthread_cond_signal or
+ * pthread_cond_broadcast.
*
* RESULTS
- * 0 successfully created semaphore,
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSPC a required resource has been exhausted,
- * ENOSYS semaphores are not supported,
- * EPERM the process lacks appropriate privilege
+ * 0 caught condition; mutex released,
+ * EINVAL 'cond' or 'mutex' is invalid,
+ * EINVAL different mutexes for concurrent waits,
+ * EINVAL mutex is not held by the calling thread,
*
* ------------------------------------------------------
*/
@@ -636,13 +653,13 @@ pthread_cond_broadcast (pthread_cond_t * cond)
* waking all current waiters.
*
* PARAMETERS
- * sem
+ * cond
* pointer to an instance of pthread_cond_t
*
*
* DESCRIPTION
- * This function initializes an unnamed semaphore. The
- * initial value of the semaphore is set to 'value'.
+ * This function signals a condition variable, waking
+ * all waiting threads.
*
* NOTES:
* 1) This function MUST be called under the protection
@@ -657,7 +674,8 @@ pthread_cond_broadcast (pthread_cond_t * cond)
* not be able to respond
*
* RESULTS
- * 0 successfully created semaphore,
+ * 0 successfully signalled condition to all
+ * waiting threads,
* EINVAL 'cond' is invalid
* ENOSPC a required resource has been exhausted,
*
@@ -679,7 +697,7 @@ pthread_cond_broadcast (pthread_cond_t * cond)
result = sem_post (&(cv->sema));
}
- if (result == 0)
+ if (cv->waiters > 0 && result == 0)
{
/*
* Wait for all the awakened threads to acquire their part of