123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include "pthread.h"
- #include "semaphore.h"
- #include "implement.h"
- int
- sem_getvalue (sem_t * sem, int *sval)
- {
- if (sem == NULL || *sem == NULL || sval == NULL)
- {
- errno = EINVAL;
- return -1;
- }
- else
- {
- long value;
- register sem_t s = *sem;
- int result = 0;
- if ((result = pthread_mutex_lock(&s->lock)) == 0)
- {
-
- if (*sem == NULL)
- {
- (void) pthread_mutex_unlock (&s->lock);
- errno = EINVAL;
- return -1;
- }
- value = s->value;
- (void) pthread_mutex_unlock(&s->lock);
- *sval = value;
- }
- return result;
- }
- }
|