diff options
author | rpj <rpj> | 2004-05-17 01:38:02 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-05-17 01:38:02 +0000 |
commit | 771465fed0cf50ee2dd790723245fc091699c324 (patch) | |
tree | d8c18d095a33fe7c4564bd90c5f313bb9e4057dd /pthread_rwlock_destroy.c | |
parent | 8b14911744f58cbe3730703f3fcc41cd969fd0f3 (diff) |
re-indentation, bug fixes, hooks for pre-emptive async cancelation
Diffstat (limited to 'pthread_rwlock_destroy.c')
-rw-r--r-- | pthread_rwlock_destroy.c | 169 |
1 files changed, 86 insertions, 83 deletions
diff --git a/pthread_rwlock_destroy.c b/pthread_rwlock_destroy.c index f759ed0..63d0cfd 100644 --- a/pthread_rwlock_destroy.c +++ b/pthread_rwlock_destroy.c @@ -41,100 +41,103 @@ #include "implement.h" int -pthread_rwlock_destroy(pthread_rwlock_t *rwlock) +pthread_rwlock_destroy (pthread_rwlock_t * rwlock) { - pthread_rwlock_t rwl; - int result = 0, result1 = 0, result2 = 0; + pthread_rwlock_t rwl; + int result = 0, result1 = 0, result2 = 0; - if (rwlock == NULL || *rwlock == NULL) - { - return EINVAL; - } + if (rwlock == NULL || *rwlock == NULL) + { + return EINVAL; + } - if (*rwlock != PTHREAD_RWLOCK_INITIALIZER) - { - rwl = *rwlock; + if (*rwlock != PTHREAD_RWLOCK_INITIALIZER) + { + rwl = *rwlock; - if (rwl->nMagic != PTW32_RWLOCK_MAGIC) - { - return EINVAL; - } + if (rwl->nMagic != PTW32_RWLOCK_MAGIC) + { + return EINVAL; + } - if ((result = pthread_mutex_lock(&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } + if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0) + { + return result; + } - if ((result = pthread_mutex_lock(&(rwl->mtxSharedAccessCompleted))) != 0) - { - (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess)); - return result; - } + if ((result = + pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0) + { + (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); + return result; + } - /* - * Check whether any threads own/wait for the lock (wait for ex.access); - * report "BUSY" if so. - */ - if (rwl->nExclusiveAccessCount > 0 - || rwl->nSharedAccessCount > rwl->nCompletedSharedAccessCount) - { - result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted)); - result1 = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess)); - result2 = EBUSY; - } - else - { - rwl->nMagic = 0; + /* + * Check whether any threads own/wait for the lock (wait for ex.access); + * report "BUSY" if so. + */ + if (rwl->nExclusiveAccessCount > 0 + || rwl->nSharedAccessCount > rwl->nCompletedSharedAccessCount) + { + result = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted)); + result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); + result2 = EBUSY; + } + else + { + rwl->nMagic = 0; - if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0) - { - pthread_mutex_unlock(&rwl->mtxExclusiveAccess); - return result; - } + if ((result = + pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0) + { + pthread_mutex_unlock (&rwl->mtxExclusiveAccess); + return result; + } - if ((result = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess))) != 0) - { - return result; - } + if ((result = + pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))) != 0) + { + return result; + } - *rwlock = NULL; /* Invalidate rwlock before anything else */ - result = pthread_cond_destroy(&(rwl->cndSharedAccessCompleted)); - result1 = pthread_mutex_destroy(&(rwl->mtxSharedAccessCompleted)); - result2 = pthread_mutex_destroy(&(rwl->mtxExclusiveAccess)); - (void) free(rwl); - } - } - else - { - /* - * See notes in ptw32_rwlock_check_need_init() above also. - */ - EnterCriticalSection(&ptw32_rwlock_test_init_lock); + *rwlock = NULL; /* Invalidate rwlock before anything else */ + result = pthread_cond_destroy (&(rwl->cndSharedAccessCompleted)); + result1 = pthread_mutex_destroy (&(rwl->mtxSharedAccessCompleted)); + result2 = pthread_mutex_destroy (&(rwl->mtxExclusiveAccess)); + (void) free (rwl); + } + } + else + { + /* + * See notes in ptw32_rwlock_check_need_init() above also. + */ + EnterCriticalSection (&ptw32_rwlock_test_init_lock); - /* - * Check again. - */ - if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) - { - /* - * This is all we need to do to destroy a statically - * initialised rwlock that has not yet been used (initialised). - * If we get to here, another thread - * waiting to initialise this rwlock will get an EINVAL. - */ - *rwlock = NULL; - } - else - { - /* - * The rwlock has been initialised while we were waiting - * so assume it's in use. - */ - result = EBUSY; - } + /* + * Check again. + */ + if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) + { + /* + * This is all we need to do to destroy a statically + * initialised rwlock that has not yet been used (initialised). + * If we get to here, another thread + * waiting to initialise this rwlock will get an EINVAL. + */ + *rwlock = NULL; + } + else + { + /* + * The rwlock has been initialised while we were waiting + * so assume it's in use. + */ + result = EBUSY; + } - LeaveCriticalSection(&ptw32_rwlock_test_init_lock); - } + LeaveCriticalSection (&ptw32_rwlock_test_init_lock); + } - return ((result != 0) ? result : ((result1 != 0) ? result1 : result2)); + return ((result != 0) ? result : ((result1 != 0) ? result1 : result2)); } |