summaryrefslogtreecommitdiff
path: root/sem_trywait.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 /sem_trywait.c
parentf84df26e12431bb9ecd07fbc52c804538635901f (diff)
Changes to mutexes and semaphores - considered alpha for now
Diffstat (limited to 'sem_trywait.c')
-rw-r--r--sem_trywait.c14
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)