b35da023cc2ee1aed4c57d6ba45fb3b5d5e88bb6
[yaz-moved-to-github.git] / test / tstlogthread.c
1 /*
2  * Copyright (c) 1998-2007, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: tstlogthread.c,v 1.6 2007-04-18 11:50:47 mike Exp $
6  */
7
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <assert.h>
13 #include <stdlib.h>
14 #include <yaz/log.h>
15 #include <yaz/options.h>
16
17 #if YAZ_POSIX_THREADS
18 #include <pthread.h>
19
20
21 static void *t_loop2(void *vp)
22 {
23     int i, sz = 10;
24
25     for (i = 0; i<sz; i++)
26     {
27 #if 0
28         fprintf(stderr, "pr %d\n", i);
29 #else
30         yaz_log(YLOG_LOG, "pr %d", i);
31 #endif
32     }
33     return 0;
34 }
35
36 static void t_test(void)
37 {
38     pthread_t tids[4];
39     
40     pthread_create(tids+0, 0, t_loop2, 0);
41     pthread_create(tids+1, 0, t_loop2, 0);
42     pthread_create(tids+2, 0, t_loop2, 0);
43     pthread_create(tids+3, 0, t_loop2, 0);
44     
45     pthread_join(tids[0], 0);
46     pthread_join(tids[1], 0);
47     pthread_join(tids[2], 0);
48     pthread_join(tids[3], 0);
49     exit(0);
50 }
51 #else
52 static void t_test(void)
53 {
54 }
55
56 #endif
57
58 int main(int argc, char **argv)
59 {
60     char *arg;
61     int ret;
62
63     /* t_test is only invoked if a non-option arg is given .. */
64     while ((ret = options("v:l:", argv, argc, &arg)) != -2)
65     {
66         switch (ret)
67         {
68         case 'v':
69             yaz_log_init_level (yaz_log_mask_str(arg));
70             break;
71         case 'l':
72             yaz_log_init_file(arg);
73             break;
74         case 0:
75             t_test();
76             break;
77         default:
78             exit(1);
79         }
80     }
81     return 0;
82 }
83 /*
84  * Local variables:
85  * c-basic-offset: 4
86  * indent-tabs-mode: nil
87  * End:
88  * vim: shiftwidth=4 tabstop=8 expandtab
89  */
90