summaryrefslogtreecommitdiff
path: root/pthread_cond_wait.c
diff options
context:
space:
mode:
Diffstat (limited to 'pthread_cond_wait.c')
-rw-r--r--pthread_cond_wait.c124
1 files changed, 62 insertions, 62 deletions
diff --git a/pthread_cond_wait.c b/pthread_cond_wait.c
index cfd1ee8..57fc978 100644
--- a/pthread_cond_wait.c
+++ b/pthread_cond_wait.c
@@ -265,19 +265,21 @@
* Arguments for cond_wait_cleanup, since we can only pass a
* single void * to it.
*/
-typedef struct {
- pthread_mutex_t * mutexPtr;
+typedef struct
+{
+ pthread_mutex_t *mutexPtr;
pthread_cond_t cv;
- int * resultPtr;
+ int *resultPtr;
int signaled;
} ptw32_cond_wait_cleanup_args_t;
-static void
-ptw32_cond_wait_cleanup(void * args)
+static void PTW32_CDECL
+ptw32_cond_wait_cleanup (void *args)
{
- ptw32_cond_wait_cleanup_args_t * cleanup_args = (ptw32_cond_wait_cleanup_args_t *) args;
+ ptw32_cond_wait_cleanup_args_t *cleanup_args =
+ (ptw32_cond_wait_cleanup_args_t *) args;
pthread_cond_t cv = cleanup_args->cv;
- int * resultPtr = cleanup_args->resultPtr;
+ int *resultPtr = cleanup_args->resultPtr;
int nSignalsWasLeft;
int result;
@@ -287,72 +289,71 @@ ptw32_cond_wait_cleanup(void * args)
* longer waiting. The waiter is responsible for adjusting waiters
* (to)unblock(ed) counts (protected by unblock lock).
*/
- if ((result = pthread_mutex_lock(&(cv->mtxUnblockLock))) != 0)
+ if ((result = pthread_mutex_lock (&(cv->mtxUnblockLock))) != 0)
{
*resultPtr = result;
return;
}
- if ( 0 != (nSignalsWasLeft = cv->nWaitersToUnblock) )
+ if (0 != (nSignalsWasLeft = cv->nWaitersToUnblock))
{
--(cv->nWaitersToUnblock);
}
- else if ( INT_MAX/2 == ++(cv->nWaitersGone) )
+ else if (INT_MAX / 2 == ++(cv->nWaitersGone))
{
- if (sem_wait( &(cv->semBlockLock) ) != 0)
- {
- *resultPtr = errno;
- /*
- * This is a fatal error for this CV,
- * so we deliberately don't unlock
- * cv->mtxUnblockLock before returning.
- */
- return;
- }
+ if (sem_wait (&(cv->semBlockLock)) != 0)
+ {
+ *resultPtr = errno;
+ /*
+ * This is a fatal error for this CV,
+ * so we deliberately don't unlock
+ * cv->mtxUnblockLock before returning.
+ */
+ return;
+ }
cv->nWaitersBlocked -= cv->nWaitersGone;
- if (sem_post( &(cv->semBlockLock) ) != 0)
- {
- *resultPtr = errno;
- /*
- * This is a fatal error for this CV,
- * so we deliberately don't unlock
- * cv->mtxUnblockLock before returning.
- */
- return;
- }
+ if (sem_post (&(cv->semBlockLock)) != 0)
+ {
+ *resultPtr = errno;
+ /*
+ * This is a fatal error for this CV,
+ * so we deliberately don't unlock
+ * cv->mtxUnblockLock before returning.
+ */
+ return;
+ }
cv->nWaitersGone = 0;
}
- if ((result = pthread_mutex_unlock(&(cv->mtxUnblockLock))) != 0)
+ if ((result = pthread_mutex_unlock (&(cv->mtxUnblockLock))) != 0)
{
*resultPtr = result;
return;
}
- if ( 1 == nSignalsWasLeft )
+ if (1 == nSignalsWasLeft)
{
- if (sem_post(&(cv->semBlockLock)) != 0)
- {
- *resultPtr = errno;
- return;
- }
+ if (sem_post (&(cv->semBlockLock)) != 0)
+ {
+ *resultPtr = errno;
+ return;
+ }
}
/*
* XSH: Upon successful return, the mutex has been locked and is owned
* by the calling thread
*/
- if ((result = pthread_mutex_lock(cleanup_args->mutexPtr)) != 0)
+ if ((result = pthread_mutex_lock (cleanup_args->mutexPtr)) != 0)
{
*resultPtr = result;
}
-} /* ptw32_cond_wait_cleanup */
+} /* ptw32_cond_wait_cleanup */
static INLINE int
-ptw32_cond_timedwait (pthread_cond_t * cond,
- pthread_mutex_t * mutex,
- const struct timespec *abstime)
+ptw32_cond_timedwait (pthread_cond_t * cond,
+ pthread_mutex_t * mutex, const struct timespec *abstime)
{
int result = 0;
pthread_cond_t cv;
@@ -371,7 +372,7 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
*/
if (*cond == PTHREAD_COND_INITIALIZER)
{
- result = ptw32_cond_check_need_init(cond);
+ result = ptw32_cond_check_need_init (cond);
}
if (result != 0 && result != EBUSY)
@@ -381,14 +382,14 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
cv = *cond;
- if (sem_wait(&(cv->semBlockLock)) != 0)
+ if (sem_wait (&(cv->semBlockLock)) != 0)
{
return errno;
}
++(cv->nWaitersBlocked);
- if (sem_post(&(cv->semBlockLock)) != 0)
+ if (sem_post (&(cv->semBlockLock)) != 0)
{
return errno;
}
@@ -409,12 +410,12 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
#ifdef _MSC_VER
#pragma inline_depth(0)
#endif
- pthread_cleanup_push(ptw32_cond_wait_cleanup, (void *) &cleanup_args);
+ pthread_cleanup_push (ptw32_cond_wait_cleanup, (void *) &cleanup_args);
/*
* Now we can release 'mutex' and...
*/
- if ((result = pthread_mutex_unlock(mutex)) == 0)
+ if ((result = pthread_mutex_unlock (mutex)) == 0)
{
/*
@@ -433,10 +434,10 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
* re-lock the mutex and adjust (to)unblock(ed) waiters
* counts if we are cancelled, timed out or signalled.
*/
- if (sem_timedwait(&(cv->semBlockQueue), abstime) != 0)
- {
- result = errno;
- }
+ if (sem_timedwait (&(cv->semBlockQueue), abstime) != 0)
+ {
+ result = errno;
+ }
}
/*
@@ -447,7 +448,7 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
/*
* Always cleanup
*/
- pthread_cleanup_pop(1);
+ pthread_cleanup_pop (1);
#ifdef _MSC_VER
#pragma inline_depth()
#endif
@@ -457,12 +458,11 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
*/
return result;
-} /* ptw32_cond_timedwait */
+} /* ptw32_cond_timedwait */
int
-pthread_cond_wait (pthread_cond_t * cond,
- pthread_mutex_t * mutex)
+pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -514,15 +514,15 @@ pthread_cond_wait (pthread_cond_t * cond,
/*
* The NULL abstime arg means INFINITE waiting.
*/
- return (ptw32_cond_timedwait(cond, mutex, NULL));
+ return (ptw32_cond_timedwait (cond, mutex, NULL));
-} /* pthread_cond_wait */
+} /* pthread_cond_wait */
int
-pthread_cond_timedwait (pthread_cond_t * cond,
- pthread_mutex_t * mutex,
- const struct timespec *abstime)
+pthread_cond_timedwait (pthread_cond_t * cond,
+ pthread_mutex_t * mutex,
+ const struct timespec *abstime)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -573,6 +573,6 @@ pthread_cond_timedwait (pthread_cond_t * cond,
return EINVAL;
}
- return (ptw32_cond_timedwait(cond, mutex, abstime));
+ return (ptw32_cond_timedwait (cond, mutex, abstime));
-} /* pthread_cond_timedwait */
+} /* pthread_cond_timedwait */