123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "pthread.h"
- #include "semaphore.h"
- #include "implement.h"
- int
- sem_post_multiple (sem_t * sem, int count)
- {
- int result = 0;
- long waiters;
- sem_t s = *sem;
- if (s == NULL || count <= 0)
- {
- result = EINVAL;
- }
- else if ((result = pthread_mutex_lock (&s->lock)) == 0)
- {
-
- if (*sem == NULL)
- {
- (void) pthread_mutex_unlock (&s->lock);
- result = EINVAL;
- return -1;
- }
- if (s->value <= (SEM_VALUE_MAX - count))
- {
- waiters = -s->value;
- s->value += count;
- if (waiters > 0)
- {
- pte_osSemaphorePost(s->sem, (waiters<=count)?waiters:count);
- result = 0;
- }
-
- }
- else
- {
- result = ERANGE;
- }
- (void) pthread_mutex_unlock (&s->lock);
- }
- if (result != 0)
- {
- errno = result;
- return -1;
- }
- return 0;
- }
|