diff options
author | rpj <rpj> | 2004-10-23 09:15:53 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-10-23 09:15:53 +0000 |
commit | cccaf0c2c82e78a72d69a4a50c872f308bed2f65 (patch) | |
tree | c5f646409ac5694c6176bf8ef72d507dd4f78089 /sem_wait.c | |
parent | 045278e11b53fc1ad59945427feab1cd9275988f (diff) |
Mutex and Semaphore changes - considered alpha for now
Diffstat (limited to 'sem_wait.c')
-rw-r--r-- | sem_wait.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -45,7 +45,7 @@ #include "semaphore.h" #include "implement.h" -static void +static inline void ptw32_sem_wait_cleanup(void * sem) { sem_t s = (sem_t) sem; @@ -53,6 +53,7 @@ ptw32_sem_wait_cleanup(void * sem) if (pthread_mutex_lock (&s->lock) == 0) { s->value++; + ReleaseSemaphore(s->sem, 1, 0); (void) pthread_mutex_unlock (&s->lock); } } @@ -115,7 +116,13 @@ sem_wait (sem_t * sem) /* Must wait */ pthread_cleanup_push(ptw32_sem_wait_cleanup, s); result = pthreadCancelableWait (s->sem); - pthread_cleanup_pop(0); + /* + * Restore the semaphore counters if no longer waiting + * and not taking the semaphore. This will occur if the + * thread is cancelled while waiting, or the wake was + * not the result of a post event given to us. + */ + pthread_cleanup_pop(result); } } |