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_post_multiple.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'sem_post_multiple.c') diff --git a/sem_post_multiple.c b/sem_post_multiple.c index e30e01a..89368f0 100644 --- a/sem_post_multiple.c +++ b/sem_post_multiple.c @@ -78,9 +78,10 @@ sem_post_multiple (sem_t * sem, int count) int result = 0; #ifndef NEED_SEM long waiters; + sem_t s = *sem; #endif - if (sem == NULL || *sem == NULL || count <= 0) + if (s == NULL || count <= 0) { result = EINVAL; } @@ -88,18 +89,28 @@ sem_post_multiple (sem_t * sem, int count) #ifdef NEED_SEM else if (!ptw32_increase_semaphore (sem, count)) + { + result = EINVAL; + } #else /* NEED_SEM */ - else if ((waiters = -InterlockedExchangeAdd((LPLONG) &(*sem)->value, (LONG) count)) > 0 - && !ReleaseSemaphore((*sem)->sem, (waiters<=count)?waiters:count, 0)) - -#endif /* NEED_SEM */ - + else if ((result = pthread_mutex_lock (&s->lock)) == 0) { - result = EINVAL; + waiters = -s->value; + s->value += count; + if (waiters > 0) + { + if (!ReleaseSemaphore (s->sem, (waiters<=count)?waiters:count, 0)) + { + result = EINVAL; + } + } + (void) pthread_mutex_unlock (&s->lock); } +#endif /* NEED_SEM */ + if (result != 0) { errno = result; -- cgit v1.2.3