123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include <errno.h>
- #include <limits.h>
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_rwlock_unlock (pthread_rwlock_t * rwlock)
- {
- int result, result1;
- pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return (EINVAL);
- }
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
-
- return 0;
- }
- rwl = *rwlock;
- if (rwl->nMagic != PTE_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
- if (rwl->nExclusiveAccessCount == 0)
- {
- if ((result =
- pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- return result;
- }
- if (++rwl->nCompletedSharedAccessCount == 0)
- {
- result = pthread_cond_signal (&(rwl->cndSharedAccessCompleted));
- }
- result1 = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
- }
- else
- {
- rwl->nExclusiveAccessCount--;
- result = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
- result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
- }
- return ((result != 0) ? result : result1);
- }
|