From 461c56569f6feec66d6a9978728393a3c3ad5a9d Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 8 Feb 2012 19:58:37 +0000 Subject: * thread.cc (__pthread_cond_wait_init): New static function replacing __pthread_cond_dowait. Only check and potentially initialize cond and mutex, drop call to (*cond)->wait. (pthread_cond_timedwait): Replace call to __pthread_cond_dowait with separate calls to __pthread_cond_wait_init and (*cond)->wait to be able to initialize cond before accessing its clock_id member. (pthread_cond_wait): Ditto (more or less). --- winsup/cygwin/thread.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'winsup/cygwin/thread.cc') diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 901155a0e..5425a9354 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -2746,8 +2746,7 @@ pthread_cond_signal (pthread_cond_t *cond) } static int -__pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex, - PLARGE_INTEGER waitlength) +__pthread_cond_wait_init (pthread_cond_t *cond, pthread_mutex_t *mutex) { if (!pthread_mutex::is_good_object (mutex)) return EINVAL; @@ -2759,7 +2758,7 @@ __pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex, if (!pthread_cond::is_good_object (cond)) return EINVAL; - return (*cond)->wait (*mutex, waitlength); + return 0; } extern "C" int @@ -2775,6 +2774,10 @@ pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, pthread_testcancel (); + int err = __pthread_cond_wait_init (cond, mutex); + if (err) + return err; + /* According to SUSv3, the abstime value must be checked for validity. */ if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 @@ -2803,7 +2806,7 @@ pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, timeout.QuadPart *= -1LL; break; } - return __pthread_cond_dowait (cond, mutex, &timeout); + return (*cond)->wait (*mutex, &timeout); } extern "C" int @@ -2811,7 +2814,10 @@ pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) { pthread_testcancel (); - return __pthread_cond_dowait (cond, mutex, NULL); + int err = __pthread_cond_wait_init (cond, mutex); + if (err) + return err; + return (*cond)->wait (*mutex, NULL); } extern "C" int -- cgit v1.2.3