summaryrefslogtreecommitdiff
path: root/sem_timedwait.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-10-23 09:15:53 +0000
committerrpj <rpj>2004-10-23 09:15:53 +0000
commitcccaf0c2c82e78a72d69a4a50c872f308bed2f65 (patch)
treec5f646409ac5694c6176bf8ef72d507dd4f78089 /sem_timedwait.c
parent045278e11b53fc1ad59945427feab1cd9275988f (diff)
Mutex and Semaphore changes - considered alpha for now
Diffstat (limited to 'sem_timedwait.c')
-rw-r--r--sem_timedwait.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/sem_timedwait.c b/sem_timedwait.c
index 7282a97..d1d9d37 100644
--- a/sem_timedwait.c
+++ b/sem_timedwait.c
@@ -52,7 +52,7 @@
#include "semaphore.h"
#include "implement.h"
-static void
+static inline void
ptw32_sem_timedwait_cleanup (void * sem)
{
sem_t s = (sem_t) sem;
@@ -60,6 +60,7 @@ ptw32_sem_timedwait_cleanup (void * sem)
if (pthread_mutex_lock (&s->lock) == 0)
{
s->value++;
+ ReleaseSemaphore(s->sem, 1, 0);
(void) pthread_mutex_unlock (&s->lock);
}
}
@@ -211,13 +212,13 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
/* Must wait */
pthread_cleanup_push(ptw32_sem_timedwait_cleanup, s);
result = pthreadCancelableTimedWait (s->sem, milliseconds);
- pthread_cleanup_pop(0);
- if (result != 0
- && pthread_mutex_lock (&s->lock) == 0)
- {
- s->value++;
- (void) pthread_mutex_unlock (&s->lock);
- }
+ /*
+ * 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, e.g. a timeout.
+ */
+ pthread_cleanup_pop(result);
}
}