diff options
author | rpj <rpj> | 2005-04-28 04:42:48 +0000 |
---|---|---|
committer | rpj <rpj> | 2005-04-28 04:42:48 +0000 |
commit | cf42850c77554311e62d3780f6a36cbc38e5e002 (patch) | |
tree | dd390776e3242c66b6e00f265f51809bdedaf5d3 /sem_wait.c | |
parent | c9dd6d65d793e97b131db8d36e0fa0a282bcea43 (diff) |
''
Diffstat (limited to 'sem_wait.c')
-rw-r--r-- | sem_wait.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -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); } } |