X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Ftest_mutex.c;h=52853b14cad0e17c0fd13f3b6f7eac5eb0126cb4;hb=25a6ea02602402282c3dd58ec922a792d4aa055f;hp=66d648168a1ce3105a27f88252df5e2d54b93197;hpb=6bc9db9f9f6944f86f1337a9a4f1e232678afc7b;p=yaz-moved-to-github.git diff --git a/test/test_mutex.c b/test/test_mutex.c index 66d6481..52853b1 100644 --- a/test/test_mutex.c +++ b/test/test_mutex.c @@ -7,10 +7,18 @@ #include #include +#if HAVE_SYS_TIME_H +#include +#endif +#ifdef WIN32 +#include +#endif + #include #include +#include -static void tst(void) +static void tst_mutex(void) { YAZ_MUTEX p = 0; @@ -28,13 +36,47 @@ static void tst(void) yaz_mutex_leave(p); yaz_mutex_destroy(&p); YAZ_CHECK(p == 0); + + yaz_mutex_destroy(&p); /* OK to "destroy" NULL handle */ +} + +static void tst_cond(void) +{ + YAZ_MUTEX p = 0; + YAZ_COND c; + struct timeval abstime; + int r; + + yaz_mutex_create(&p); + YAZ_CHECK(p); + if (!p) + 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); + + 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; }