From f8af93c39f8deebc46aee1b25be9d5c40035d0d8 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 14 Mar 1999 05:29:18 +0000 Subject: Mon Mar 15 00:20:13 1999 Ross Johnson * condvar.c (pthread_cond_init): fix possible uninitialised use of cv. Sun Mar 14 21:01:59 1999 Ross Johnson * condvar.c (pthread_cond_destroy): don't do full cleanup if static initialised cv has never been used. (cond_timedwait): check result of auto-initialisation. tests/ChangeLog Mon Mar 15 00:17:55 1999 Ross Johnson * mutex1.c: only test mutex init and destroy; add assertions. * count1.c: raise number of spawned threads to 60 (appears to be the limit under Win98). Sun Mar 14 21:31:02 1999 Ross Johnson * test.h (assert): add assertion trace option. Use: "#define ASSERT_TRACE 1" to turn it on, "#define ASSERT_TRACE 0" to turn it off (default). * condvar3.c (main): add more assertions. * condvar4.c (main): add more assertions. * condvar1.c (main): add more assertions. --- condvar.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'condvar.c') diff --git a/condvar.c b/condvar.c index 80dc1c4..ce46ebf 100644 --- a/condvar.c +++ b/condvar.c @@ -327,7 +327,7 @@ pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr) */ { int result = EAGAIN; - pthread_cond_t cv; + pthread_cond_t cv = NULL; if (cond == NULL) { @@ -443,16 +443,20 @@ pthread_cond_destroy (pthread_cond_t * cond) cv = *cond; - if (cv->waiters > 0) + if (cv != (pthread_cond_t) _PTHREAD_OBJECT_AUTO_INIT) { - return EBUSY; - } + if (cv->waiters > 0) + { + return EBUSY; + } - (void) _pthread_sem_destroy (&(cv->sema)); - (void) pthread_mutex_destroy (&(cv->waitersLock)); - (void) CloseHandle (cv->waitersDone); + (void) _pthread_sem_destroy (&(cv->sema)); + (void) pthread_mutex_destroy (&(cv->waitersLock)); + (void) CloseHandle (cv->waitersDone); + + free(cv); + } - free(cv); *cond = NULL; return (result); @@ -473,19 +477,24 @@ cond_timedwait (pthread_cond_t * cond, return EINVAL; } - cv = *cond; - /* * We do a quick check to see if we need to do more work * to initialise a static condition variable. We check * again inside the guarded section of _cond_check_need_init() * to avoid race conditions. */ - if (cv == (pthread_cond_t) _PTHREAD_OBJECT_AUTO_INIT) + if (*cond == (pthread_cond_t) _PTHREAD_OBJECT_AUTO_INIT) { result = _cond_check_need_init(cond); } + if (result != 0 && result != EBUSY) + { + return result; + } + + cv = *cond; + /* * OK to increment cond->waiters because the caller locked 'mutex' */ -- cgit v1.2.3