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