No more manifest files
[yaz-moved-to-github.git] / src / init_globals.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file init_globals.c
8  * \brief Initialize global things
9  */
10
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include <yaz/log.h>
16
17 #if YAZ_POSIX_THREADS
18 #include <pthread.h>
19 #endif
20 #include <errno.h>
21
22 #if HAVE_GNUTLS_H
23 #include <gnutls/gnutls.h>
24 #endif
25
26 #if YAZ_HAVE_XML2
27 #include <libxml/parser.h>
28 #endif
29
30 #if YAZ_HAVE_XSLT
31 #include <libxslt/xslt.h>
32 #endif
33
34 #if YAZ_HAVE_EXSLT
35 #include <libexslt/exslt.h>
36 #endif
37
38 static int yaz_init_flag = 0;
39 #if YAZ_POSIX_THREADS
40 static pthread_mutex_t yaz_init_mutex = PTHREAD_MUTEX_INITIALIZER;
41 #endif
42
43 extern void yaz_log_init_globals(void);
44 extern void yaz_log_deinit_globals(void);
45
46 void yaz_init_globals(void)
47 {
48     if (yaz_init_flag)
49         return;
50 #if YAZ_POSIX_THREADS
51     pthread_mutex_lock(&yaz_init_mutex);
52 #endif
53     if (!yaz_init_flag)
54     {
55         yaz_log_init_globals();
56 #if HAVE_GNUTLS_H
57         gnutls_global_init();
58 #endif
59 #if YAZ_HAVE_XML2
60         xmlInitParser();
61 #endif
62 #if YAZ_HAVE_XSLT
63         xsltInit();
64 #endif
65 #if YAZ_HAVE_EXSLT
66         exsltRegisterAll();
67 #endif
68         yaz_init_flag = 1; /* must be last, before unlocking */
69     }
70 #if YAZ_POSIX_THREADS
71     pthread_mutex_unlock(&yaz_init_mutex);
72 #endif
73 }
74
75 void yaz_deinit_globals(void)
76 {
77     if (!yaz_init_flag)
78         return;
79 #if YAZ_POSIX_THREADS
80     pthread_mutex_lock(&yaz_init_mutex);
81 #endif
82     if (yaz_init_flag)
83     {
84         yaz_log_deinit_globals();
85 #if HAVE_GNUTLS_H
86         gnutls_global_deinit();
87 #endif
88 #if YAZ_HAVE_XSLT
89         xsltCleanupGlobals();
90 #endif
91 #if YAZ_HAVE_XML2
92         xmlCleanupParser();
93 #endif
94         yaz_init_flag = 0;
95     }
96 #if YAZ_POSIX_THREADS
97     pthread_mutex_unlock(&yaz_init_mutex);
98 #endif
99 }
100
101 /*
102  * Local variables:
103  * c-basic-offset: 4
104  * c-file-style: "Stroustrup"
105  * indent-tabs-mode: nil
106  * End:
107  * vim: shiftwidth=4 tabstop=8 expandtab
108  */
109