From 045278e11b53fc1ad59945427feab1cd9275988f Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 22 Oct 2004 15:06:41 +0000 Subject: Changes to mutexes and semaphores - considered alpha for now --- sem_trywait.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sem_trywait.c') diff --git a/sem_trywait.c b/sem_trywait.c index 253c10e..fbc457c 100644 --- a/sem_trywait.c +++ b/sem_trywait.c @@ -87,15 +87,21 @@ sem_trywait (sem_t * sem) #else /* NEED_SEM */ int result = 0; + sem_t s = *sem; - if (sem == NULL || *sem == NULL) + if (s == NULL) { result = EINVAL; } - else if (InterlockedDecrement((LPLONG) &(*sem)->value) < 0) + else if ((result = pthread_mutex_lock (&s->lock)) == 0) { - (void) InterlockedIncrement((LPLONG) &(*sem)->value); - result = EAGAIN; + if (--s->value < 0) + { + s->value++; + result = EAGAIN; + } + + (void) pthread_mutex_unlock (&s->lock); } if (result != 0) -- cgit v1.2.3