From: Adam Dickmeiss Date: Tue, 27 Apr 2010 13:59:21 +0000 (+0200) Subject: Simple test of yaz_cond_wait X-Git-Tag: v4.0.4~11 X-Git-Url: http://jsfdemo.indexdata.com/?a=commitdiff_plain;h=e45adb79ab73280e963c849927707089d4031040;p=yaz-moved-to-github.git Simple test of yaz_cond_wait --- diff --git a/test/test_mutex.c b/test/test_mutex.c index 843ea8f..9cef383 100644 --- a/test/test_mutex.c +++ b/test/test_mutex.c @@ -7,10 +7,11 @@ #include #include +#include #include #include -static void tst(void) +static void tst_mutex(void) { YAZ_MUTEX p = 0; @@ -32,11 +33,45 @@ static void tst(void) yaz_mutex_destroy(&p); /* OK to "destroy" NULL handle */ } +static void tst_cond(void) +{ + YAZ_MUTEX p = 0; + YAZ_COND c; + struct timespec abstime; + struct timeval tval; + int r; + + yaz_mutex_create(&p); + YAZ_CHECK(p); + if (!p) + return; + + yaz_cond_create(&c); + YAZ_CHECK(c); + if (!c) + return; + + r = gettimeofday(&tval, 0); + YAZ_CHECK_EQ(r, 0); + + abstime.tv_sec = tval.tv_sec + 1; /* wait 2 seconds */ + abstime.tv_nsec = tval.tv_usec * 1000; + + r = yaz_cond_wait(c, p, &abstime); + YAZ_CHECK(r != 0); + + yaz_cond_destroy(&c); + YAZ_CHECK(c == 0); + yaz_mutex_destroy(&p); + YAZ_CHECK(p == 0); +} + int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); - tst(); + tst_mutex(); + tst_cond(); YAZ_CHECK_TERM; }