diff options
author | rpj <rpj> | 2005-05-06 07:31:28 +0000 |
---|---|---|
committer | rpj <rpj> | 2005-05-06 07:31:28 +0000 |
commit | 78f83cfa240ec14874b22c7302ff8d306c130aaf (patch) | |
tree | bf29a117aecb99e9ecb2d30bad398d8b20392b49 /sem_post_multiple.c | |
parent | e3845d9b6b0a18ffdfdf0cefd811a17fce62f1ac (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); } |