diff options
author | rpj <rpj> | 2005-04-28 04:41:25 +0000 |
---|---|---|
committer | rpj <rpj> | 2005-04-28 04:41:25 +0000 |
commit | 1abb2a28b3947feaf38a85b59e3f3a8c03804ceb (patch) | |
tree | dc66cbad6f00d7a685d79790c9626bda58bf8f4f /sem_wait.c | |
parent | 7966f36b14fe041eba56283d424cee997c390016 (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); } } |