Fix SEGV yaz-client with SRU target www.bergen.folkebibl.no/cgi-bin/sru YAZ-829
[yaz-moved-to-github.git] / test / test_mutex.c
index 6a0b9f1..2327b8e 100644 (file)
@@ -1,7 +1,10 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -54,18 +57,17 @@ static void tst_cond(void)
         return;
 
     yaz_cond_create(&c);
-    YAZ_CHECK(c);
-    if (!c)
-        return;
+    if (c)
+    {
+        r = yaz_gettimeofday(&abstime);
+        YAZ_CHECK_EQ(r, 0);
+
+        abstime.tv_sec += 1; /* wait 1 second */
 
-    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);
+        r = yaz_cond_wait(c, p, &abstime);
+        YAZ_CHECK(r != 0);
 
+    }
     yaz_cond_destroy(&c);
     YAZ_CHECK(c == 0);
     yaz_mutex_destroy(&p);
@@ -82,25 +84,27 @@ static void *my_handler(void *arg)
 static void tst_create_thread(void)
 {
     void *return_data;
-    int mydata = 42;
+    int mydata0 = 42;
+    int mydata1= 42;
     yaz_thread_t t[2];
 
-    t[0] = yaz_thread_create(my_handler, &mydata);
+    t[0] = yaz_thread_create(my_handler, &mydata0);
     YAZ_CHECK(t[0]);
-    t[1] = yaz_thread_create(my_handler, &mydata);
+    t[1] = yaz_thread_create(my_handler, &mydata1);
     YAZ_CHECK(t[1]);
-    
+
     return_data = 0;
     yaz_thread_join(&t[0], &return_data);
     YAZ_CHECK(!t[0]);
-    YAZ_CHECK(return_data == &mydata);
+    YAZ_CHECK(return_data == &mydata0);
 
     return_data = 0;
     yaz_thread_join(&t[1], &return_data);
     YAZ_CHECK(!t[1]);
-    YAZ_CHECK(return_data == &mydata);
-    
-    YAZ_CHECK_EQ(mydata, 44);
+    YAZ_CHECK(return_data == &mydata1);
+
+    YAZ_CHECK_EQ(mydata0, 43);
+    YAZ_CHECK_EQ(mydata1, 43);
 }
 
 int main (int argc, char **argv)