summaryrefslogtreecommitdiff
path: root/ptw32_semwait.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-10-22 15:06:41 +0000
committerrpj <rpj>2004-10-22 15:06:41 +0000
commit045278e11b53fc1ad59945427feab1cd9275988f (patch)
treeda8570a7a8962d9563814c4910e8a9d5fb6fa685 /ptw32_semwait.c
parentf84df26e12431bb9ecd07fbc52c804538635901f (diff)
Changes to mutexes and semaphores - considered alpha for now
Diffstat (limited to 'ptw32_semwait.c')
-rw-r--r--ptw32_semwait.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/ptw32_semwait.c b/ptw32_semwait.c
index 2e9c883..e8b7ace 100644
--- a/ptw32_semwait.c
+++ b/ptw32_semwait.c
@@ -67,10 +67,10 @@ ptw32_semwait (sem_t * sem)
*/
{
int result = 0;
-
DWORD status;
+ sem_t s = *sem;
- if (sem == NULL)
+ if (s == NULL)
{
result = EINVAL;
}
@@ -79,19 +79,30 @@ ptw32_semwait (sem_t * sem)
#ifdef NEED_SEM
- status = WaitForSingleObject ((*sem)->event, INFINITE);
+ status = WaitForSingleObject (s->event, INFINITE);
#else /* NEED_SEM */
- if (InterlockedDecrement((LPLONG) &(*sem)->value) < 0)
+ if ((result = pthread_mutex_lock (&s->lock)) == 0)
{
- /* Must wait */
- status = WaitForSingleObject ((*sem)->sem, INFINITE);
+ int v = --s->value;
+
+ (void) pthread_mutex_unlock (&s->lock);
+
+ if (v < 0)
+ {
+ /* Must wait */
+ status = WaitForSingleObject (s->sem, INFINITE);
+ }
+ else
+ {
+ return 0;
+ }
}
else
- {
- return 0;
- }
+ {
+ return result;
+ }
#endif
@@ -109,7 +120,7 @@ ptw32_semwait (sem_t * sem)
else
{
#ifndef NEED_SEM
- (void) InterlockedIncrement((LPLONG) &(*sem)->value);
+ (void) InterlockedIncrement((LPLONG) &s->value);
#endif
result = EINVAL;
}