* 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).
This commit is contained in:
Corinna Vinschen 2012-02-08 19:58:37 +00:00
parent 30c66cea49
commit 461c56569f
2 changed files with 21 additions and 5 deletions
winsup/cygwin

@ -1,3 +1,13 @@
2012-02-08 Corinna Vinschen <corinna@vinschen.de>
* 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).
2012-02-08 Christian Franke <franke@computer.org> 2012-02-08 Christian Franke <franke@computer.org>
* include/sys/wait.h: Remove C++ inline functions for `union wait'. * include/sys/wait.h: Remove C++ inline functions for `union wait'.

@ -2746,8 +2746,7 @@ pthread_cond_signal (pthread_cond_t *cond)
} }
static int static int
__pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex, __pthread_cond_wait_init (pthread_cond_t *cond, pthread_mutex_t *mutex)
PLARGE_INTEGER waitlength)
{ {
if (!pthread_mutex::is_good_object (mutex)) if (!pthread_mutex::is_good_object (mutex))
return EINVAL; return EINVAL;
@ -2759,7 +2758,7 @@ __pthread_cond_dowait (pthread_cond_t *cond, pthread_mutex_t *mutex,
if (!pthread_cond::is_good_object (cond)) if (!pthread_cond::is_good_object (cond))
return EINVAL; return EINVAL;
return (*cond)->wait (*mutex, waitlength); return 0;
} }
extern "C" int extern "C" int
@ -2775,6 +2774,10 @@ pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
pthread_testcancel (); 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. */ /* According to SUSv3, the abstime value must be checked for validity. */
if (abstime->tv_sec < 0 if (abstime->tv_sec < 0
|| abstime->tv_nsec < 0 || abstime->tv_nsec < 0
@ -2803,7 +2806,7 @@ pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
timeout.QuadPart *= -1LL; timeout.QuadPart *= -1LL;
break; break;
} }
return __pthread_cond_dowait (cond, mutex, &timeout); return (*cond)->wait (*mutex, &timeout);
} }
extern "C" int extern "C" int
@ -2811,7 +2814,10 @@ pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
{ {
pthread_testcancel (); 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 extern "C" int