diff options
Diffstat (limited to 'sem_trywait.c')
-rw-r--r-- | sem_trywait.c | 14 |
1 files changed, 10 insertions, 4 deletions
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) |