summaryrefslogtreecommitdiff
path: root/ptw32_semwait.c
diff options
context:
space:
mode:
Diffstat (limited to 'ptw32_semwait.c')
-rw-r--r--ptw32_semwait.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/ptw32_semwait.c b/ptw32_semwait.c
index 38f31f5..2e9c883 100644
--- a/ptw32_semwait.c
+++ b/ptw32_semwait.c
@@ -83,7 +83,15 @@ ptw32_semwait (sem_t * sem)
#else /* NEED_SEM */
- status = WaitForSingleObject ((*sem)->sem, INFINITE);
+ if (InterlockedDecrement((LPLONG) &(*sem)->value) < 0)
+ {
+ /* Must wait */
+ status = WaitForSingleObject ((*sem)->sem, INFINITE);
+ }
+ else
+ {
+ return 0;
+ }
#endif
@@ -100,6 +108,9 @@ ptw32_semwait (sem_t * sem)
}
else
{
+#ifndef NEED_SEM
+ (void) InterlockedIncrement((LPLONG) &(*sem)->value);
+#endif
result = EINVAL;
}
}