summaryrefslogtreecommitdiff
path: root/pthread_rwlock_trywrlock.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-05-17 01:38:02 +0000
committerrpj <rpj>2004-05-17 01:38:02 +0000
commit771465fed0cf50ee2dd790723245fc091699c324 (patch)
treed8c18d095a33fe7c4564bd90c5f313bb9e4057dd /pthread_rwlock_trywrlock.c
parent8b14911744f58cbe3730703f3fcc41cd969fd0f3 (diff)
re-indentation, bug fixes, hooks for pre-emptive async cancelation
Diffstat (limited to 'pthread_rwlock_trywrlock.c')
-rw-r--r--pthread_rwlock_trywrlock.c131
1 files changed, 67 insertions, 64 deletions
diff --git a/pthread_rwlock_trywrlock.c b/pthread_rwlock_trywrlock.c
index 6fa92ed..543fdbf 100644
--- a/pthread_rwlock_trywrlock.c
+++ b/pthread_rwlock_trywrlock.c
@@ -41,80 +41,83 @@
#include "implement.h"
int
-pthread_rwlock_trywrlock(pthread_rwlock_t * rwlock)
+pthread_rwlock_trywrlock (pthread_rwlock_t * rwlock)
{
- int result, result1;
- pthread_rwlock_t rwl;
+ int result, result1;
+ pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
- rwl = *rwlock;
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if ((result = pthread_mutex_trylock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
+ if ((result = pthread_mutex_trylock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
- if ((result = pthread_mutex_trylock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- result1 = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return ((result1 != 0) ? result1 : result);
- }
+ if ((result =
+ pthread_mutex_trylock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return ((result1 != 0) ? result1 : result);
+ }
- if (rwl->nExclusiveAccessCount == 0)
- {
- if (rwl->nCompletedSharedAccessCount > 0)
- {
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
- }
+ if (rwl->nExclusiveAccessCount == 0)
+ {
+ if (rwl->nCompletedSharedAccessCount > 0)
+ {
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
+ }
- if (rwl->nSharedAccessCount > 0)
- {
- if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
+ if (rwl->nSharedAccessCount > 0)
+ {
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
- if ((result = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess))) == 0)
- {
- result = EBUSY;
- }
- }
- else
- {
- rwl->nExclusiveAccessCount = 1;
- }
- }
- else
- {
- result = EBUSY;
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))) == 0)
+ {
+ result = EBUSY;
+ }
+ }
+ else
+ {
+ rwl->nExclusiveAccessCount = 1;
+ }
+ }
+ else
+ {
+ result = EBUSY;
+ }
- return result;
+ return result;
}