summaryrefslogtreecommitdiff
path: root/pthread_cond_destroy.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_cond_destroy.c
parent8b14911744f58cbe3730703f3fcc41cd969fd0f3 (diff)
re-indentation, bug fixes, hooks for pre-emptive async cancelation
Diffstat (limited to 'pthread_cond_destroy.c')
-rw-r--r--pthread_cond_destroy.c163
1 files changed, 81 insertions, 82 deletions
diff --git a/pthread_cond_destroy.c b/pthread_cond_destroy.c
index 0030269..7a34068 100644
--- a/pthread_cond_destroy.c
+++ b/pthread_cond_destroy.c
@@ -120,15 +120,14 @@ pthread_cond_destroy (pthread_cond_t * cond)
/*
* Assuming any race condition here is harmless.
*/
- if (cond == NULL
- || *cond == NULL)
+ if (cond == NULL || *cond == NULL)
{
return EINVAL;
}
if (*cond != PTHREAD_COND_INITIALIZER)
{
- EnterCriticalSection(&ptw32_cond_list_lock);
+ EnterCriticalSection (&ptw32_cond_list_lock);
cv = *cond;
@@ -137,109 +136,109 @@ pthread_cond_destroy (pthread_cond_t * cond)
* all already signaled waiters to let them retract their
* waiter status - SEE NOTE 1 ABOVE!!!
*/
- if (sem_wait(&(cv->semBlockLock)) != 0)
- {
- return errno;
- }
+ if (sem_wait (&(cv->semBlockLock)) != 0)
+ {
+ return errno;
+ }
/*
* !TRY! lock mtxUnblockLock; try will detect busy condition
* and will not cause a deadlock with respect to concurrent
* signal/broadcast.
*/
- if ((result = pthread_mutex_trylock(&(cv->mtxUnblockLock))) != 0)
- {
- (void) sem_post(&(cv->semBlockLock));
- return result;
- }
+ if ((result = pthread_mutex_trylock (&(cv->mtxUnblockLock))) != 0)
+ {
+ (void) sem_post (&(cv->semBlockLock));
+ return result;
+ }
/*
* Check whether cv is still busy (still has waiters)
*/
if (cv->nWaitersBlocked > cv->nWaitersGone)
- {
- if (sem_post(&(cv->semBlockLock)) != 0)
- {
- result = errno;
- }
- result1 = pthread_mutex_unlock(&(cv->mtxUnblockLock));
- result2 = EBUSY;
- }
+ {
+ if (sem_post (&(cv->semBlockLock)) != 0)
+ {
+ result = errno;
+ }
+ result1 = pthread_mutex_unlock (&(cv->mtxUnblockLock));
+ result2 = EBUSY;
+ }
else
- {
- /*
- * Now it is safe to destroy
- */
- *cond = NULL;
-
- if (sem_destroy(&(cv->semBlockLock)) != 0)
- {
- result = errno;
- }
- if (sem_destroy(&(cv->semBlockQueue)) != 0)
- {
- result1 = errno;
- }
- if ((result2 = pthread_mutex_unlock(&(cv->mtxUnblockLock))) == 0)
- {
- result2 = pthread_mutex_destroy(&(cv->mtxUnblockLock));
- }
-
- /* Unlink the CV from the list */
-
- if (ptw32_cond_list_head == cv)
- {
- ptw32_cond_list_head = cv->next;
- }
- else
- {
- cv->prev->next = cv->next;
- }
-
- if (ptw32_cond_list_tail == cv)
- {
- ptw32_cond_list_tail = cv->prev;
- }
- else
- {
- cv->next->prev = cv->prev;
- }
-
- (void) free(cv);
- }
-
- LeaveCriticalSection(&ptw32_cond_list_lock);
+ {
+ /*
+ * Now it is safe to destroy
+ */
+ *cond = NULL;
+
+ if (sem_destroy (&(cv->semBlockLock)) != 0)
+ {
+ result = errno;
+ }
+ if (sem_destroy (&(cv->semBlockQueue)) != 0)
+ {
+ result1 = errno;
+ }
+ if ((result2 = pthread_mutex_unlock (&(cv->mtxUnblockLock))) == 0)
+ {
+ result2 = pthread_mutex_destroy (&(cv->mtxUnblockLock));
+ }
+
+ /* Unlink the CV from the list */
+
+ if (ptw32_cond_list_head == cv)
+ {
+ ptw32_cond_list_head = cv->next;
+ }
+ else
+ {
+ cv->prev->next = cv->next;
+ }
+
+ if (ptw32_cond_list_tail == cv)
+ {
+ ptw32_cond_list_tail = cv->prev;
+ }
+ else
+ {
+ cv->next->prev = cv->prev;
+ }
+
+ (void) free (cv);
+ }
+
+ LeaveCriticalSection (&ptw32_cond_list_lock);
}
else
{
/*
* See notes in ptw32_cond_check_need_init() above also.
*/
- EnterCriticalSection(&ptw32_cond_test_init_lock);
+ EnterCriticalSection (&ptw32_cond_test_init_lock);
/*
* Check again.
*/
if (*cond == PTHREAD_COND_INITIALIZER)
- {
- /*
- * This is all we need to do to destroy a statically
- * initialised cond that has not yet been used (initialised).
- * If we get to here, another thread waiting to initialise
- * this cond will get an EINVAL. That's OK.
- */
- *cond = NULL;
- }
+ {
+ /*
+ * This is all we need to do to destroy a statically
+ * initialised cond that has not yet been used (initialised).
+ * If we get to here, another thread waiting to initialise
+ * this cond will get an EINVAL. That's OK.
+ */
+ *cond = NULL;
+ }
else
- {
- /*
- * The cv has been initialised while we were waiting
- * so assume it's in use.
- */
- result = EBUSY;
- }
-
- LeaveCriticalSection(&ptw32_cond_test_init_lock);
+ {
+ /*
+ * The cv has been initialised while we were waiting
+ * so assume it's in use.
+ */
+ result = EBUSY;
+ }
+
+ LeaveCriticalSection (&ptw32_cond_test_init_lock);
}
return ((result != 0) ? result : ((result1 != 0) ? result1 : result2));