From 1e957275de39799db9449c8d6c2f52359b494799 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 19 May 2010 15:14:43 +0200 Subject: [PATCH] yaz_cond_create returns 0 if threads is unavail --- src/condvar.c | 5 ++++- test/test_mutex.c | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/condvar.c b/src/condvar.c index e6292bd..19291d4 100644 --- a/src/condvar.c +++ b/src/condvar.c @@ -48,11 +48,14 @@ struct yaz_cond { void yaz_cond_create(YAZ_COND *p) { - *p = (YAZ_COND) malloc(sizeof(**p)); #ifdef WIN32 + *p = (YAZ_COND) malloc(sizeof(**p)); InitializeConditionVariable(&(*p)->cond); #elif YAZ_POSIX_THREADS + *p = (YAZ_COND) malloc(sizeof(**p)); pthread_cond_init(&(*p)->cond, 0); +#else + *p = 0; #endif } diff --git a/test/test_mutex.c b/test/test_mutex.c index 6a0b9f1..a4483fc 100644 --- a/test/test_mutex.c +++ b/test/test_mutex.c @@ -54,18 +54,17 @@ static void tst_cond(void) return; yaz_cond_create(&c); - YAZ_CHECK(c); - if (!c) - return; - - r = yaz_gettimeofday(&abstime); - YAZ_CHECK_EQ(r, 0); - - abstime.tv_sec += 1; /* wait 1 second */ - - r = yaz_cond_wait(c, p, &abstime); - YAZ_CHECK(r != 0); - + if (c) + { + r = yaz_gettimeofday(&abstime); + YAZ_CHECK_EQ(r, 0); + + abstime.tv_sec += 1; /* wait 1 second */ + + r = yaz_cond_wait(c, p, &abstime); + YAZ_CHECK(r != 0); + + } yaz_cond_destroy(&c); YAZ_CHECK(c == 0); yaz_mutex_destroy(&p); -- 1.7.10.4