summaryrefslogtreecommitdiff
path: root/sem_wait.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-04-28 04:42:48 +0000
committerrpj <rpj>2005-04-28 04:42:48 +0000
commitcf42850c77554311e62d3780f6a36cbc38e5e002 (patch)
treedd390776e3242c66b6e00f265f51809bdedaf5d3 /sem_wait.c
parentc9dd6d65d793e97b131db8d36e0fa0a282bcea43 (diff)
''
Diffstat (limited to 'sem_wait.c')
-rw-r--r--sem_wait.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/sem_wait.c b/sem_wait.c
index bcb17e8..05d7326 100644
--- a/sem_wait.c
+++ b/sem_wait.c
@@ -53,19 +53,27 @@ ptw32_sem_wait_cleanup(void * sem)
if (pthread_mutex_lock (&s->lock) == 0)
{
- ++s->value;
-#ifdef NEED_SEM
-
- if (s->value > 0)
- {
- s->leftToUnblock = 0;
- }
-#else
/*
- * Don't release the W32 sema, it doesn't need adjustment
- * because it doesn't record the number of waiters.
+ * If the sema is posted between us being cancelled and us locking
+ * the sema again above then we need to consume that post but cancel
+ * anyway. If we don't get the semaphore we indicate that we're no
+ * longer waiting.
*/
+ if (!(WaitForSingleObject(s->sem, 0) == WAIT_OBJECT_0))
+ {
+ ++s->value;
+#ifdef NEED_SEM
+ if (s->value > 0)
+ {
+ s->leftToUnblock = 0;
+ }
+#else
+ /*
+ * Don't release the W32 sema, it doesn't need adjustment
+ * because it doesn't record the number of waiters.
+ */
#endif /* NEED_SEM */
+ }
(void) pthread_mutex_unlock (&s->lock);
}
}