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_delay_np.c | |
parent | 8b14911744f58cbe3730703f3fcc41cd969fd0f3 (diff) |
re-indentation, bug fixes, hooks for pre-emptive async cancelation
Diffstat (limited to 'pthread_delay_np.c')
-rw-r--r-- | pthread_delay_np.c | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/pthread_delay_np.c b/pthread_delay_np.c index 76a5773..ee9b2d9 100644 --- a/pthread_delay_np.c +++ b/pthread_delay_np.c @@ -79,7 +79,7 @@ * intRC = pthread_delay_np(&tsWait); */ int -pthread_delay_np (struct timespec * interval) +pthread_delay_np (struct timespec *interval) { DWORD wait_time; DWORD secs_in_millisecs; @@ -94,9 +94,9 @@ pthread_delay_np (struct timespec * interval) if (interval->tv_sec == 0L && interval->tv_nsec == 0L) { - pthread_testcancel(); - Sleep(0); - pthread_testcancel(); + pthread_testcancel (); + Sleep (0); + pthread_testcancel (); return (0); } @@ -106,12 +106,25 @@ pthread_delay_np (struct timespec * interval) /* convert nanosecs to millisecs (rounding up) */ millisecs = (interval->tv_nsec + 999999L) / 1000000L; +#if defined(__WATCOMC__) +#pragma disable_message (124) +#endif + + /* + * Most compilers will issue a warning 'comparison always 0' + * because the variable type is unsigned, but we need to keep this + * for some reason I can't recall now. + */ if (0 > (wait_time = secs_in_millisecs + millisecs)) { return EINVAL; } - if (NULL == (self = pthread_self())) +#if defined(__WATCOMC__) +#pragma enable_message (124) +#endif + + if (NULL == (self = pthread_self ())) { return ENOMEM; } @@ -123,32 +136,32 @@ pthread_delay_np (struct timespec * interval) * Deferred cancelation will cancel us immediately. */ if (WAIT_OBJECT_0 == - (status = WaitForSingleObject(self->cancelEvent, wait_time)) ) - { - /* - * Canceling! - */ - (void) pthread_mutex_lock(&self->cancelLock); - if (self->state < PThreadStateCanceling) - { - self->state = PThreadStateCanceling; - self->cancelState = PTHREAD_CANCEL_DISABLE; - (void) pthread_mutex_unlock(&self->cancelLock); + (status = WaitForSingleObject (self->cancelEvent, wait_time))) + { + /* + * Canceling! + */ + (void) pthread_mutex_lock (&self->cancelLock); + if (self->state < PThreadStateCanceling) + { + self->state = PThreadStateCanceling; + self->cancelState = PTHREAD_CANCEL_DISABLE; + (void) pthread_mutex_unlock (&self->cancelLock); - ptw32_throw(PTW32_EPS_CANCEL); - } + ptw32_throw (PTW32_EPS_CANCEL); + } - (void) pthread_mutex_unlock(&self->cancelLock); - return ESRCH; - } + (void) pthread_mutex_unlock (&self->cancelLock); + return ESRCH; + } else if (status != WAIT_TIMEOUT) - { - return EINVAL; - } + { + return EINVAL; + } } else { - Sleep( wait_time ); + Sleep (wait_time); } return (0); |