diff options
author | rpj <rpj> | 2005-05-06 07:27:10 +0000 |
---|---|---|
committer | rpj <rpj> | 2005-05-06 07:27:10 +0000 |
commit | 7523c7c4d75652f67cd31cb123e1268790394c8b (patch) | |
tree | 0920ebf089ccb971e0878542f85486171a541a8a /sem_post_multiple.c | |
parent | cf42850c77554311e62d3780f6a36cbc38e5e002 (diff) |
''
Diffstat (limited to 'sem_post_multiple.c')
-rw-r--r-- | sem_post_multiple.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/sem_post_multiple.c b/sem_post_multiple.c index 9dab861..42ea2f4 100644 --- a/sem_post_multiple.c +++ b/sem_post_multiple.c @@ -71,6 +71,7 @@ sem_post_multiple (sem_t * sem, int count) * ERRNO * EINVAL 'sem' is not a valid semaphore * or count is less than or equal to zero. + * ERANGE semaphore count is too big * * ------------------------------------------------------ */ @@ -85,28 +86,39 @@ sem_post_multiple (sem_t * sem, int count) } else if ((result = pthread_mutex_lock (&s->lock)) == 0) { - waiters = -s->value; - s->value += count; - if (waiters > 0) - { -#ifdef NEED_SEM - if (SetEvent(s->sem)) + if (s->value <= (_POSIX_SEM_VALUE_MAX - count)) + { + waiters = -s->value; + s->value += count; + if (waiters > 0) { - waiters--; - s->leftToUnblock += count - 1; - if (s->leftToUnblock > waiters) +#ifdef NEED_SEM + if (SetEvent(s->sem)) { - s->leftToUnblock = waiters; + waiters--; + s->leftToUnblock += count - 1; + if (s->leftToUnblock > waiters) + { + s->leftToUnblock = waiters; + } } - } - else #else - if (!ReleaseSemaphore (s->sem, (waiters<=count)?waiters:count, 0)) + if (ReleaseSemaphore (s->sem, (waiters<=count)?waiters:count, 0)) + { + /* No action */ + } #endif - { - result = EINVAL; - } - } + else + { + s->value -= count; + result = EINVAL; + } + } + } + else + { + result = ERANGE; + } (void) pthread_mutex_unlock (&s->lock); } |