123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "pthread.h"
- #include "semaphore.h"
- #include "implement.h"
- int
- sem_post (sem_t * sem)
- {
- int result = 0;
- sem_t s = *sem;
- if (s == NULL)
- {
- 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)
- {
- pte_osResult osResult = pte_osSemaphorePost(s->sem, 1);
- if (++s->value <= 0
- && (osResult != PTE_OS_OK))
- {
- s->value--;
- result = EINVAL;
- }
- }
- else
- {
- result = ERANGE;
- }
- (void) pthread_mutex_unlock (&s->lock);
- }
- if (result != 0)
- {
- errno = result;
- return -1;
- }
- return 0;
- }
|