Remove CQL to Solr conversion and base on cql_transform_t
[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 #if YAZ_POSIX_THREADS
16 #include <pthread.h>
17 #endif
18 #include <errno.h>
19
20 #if HAVE_GNUTLS_H
21 #include <gnutls/gnutls.h>
22 #endif
23
24 #if HAVE_GCRYPT_H
25 #include <gcrypt.h>
26 #endif
27
28 #if YAZ_HAVE_EXSLT
29 #include <libexslt/exslt.h>
30 #endif
31
32 static int yaz_init_flag = 0;
33 #if YAZ_POSIX_THREADS
34 static pthread_mutex_t yaz_init_mutex = PTHREAD_MUTEX_INITIALIZER;
35 #endif
36
37 extern void yaz_log_init_globals(void);
38
39 #if HAVE_GCRYPT_H
40 GCRY_THREAD_OPTION_PTHREAD_IMPL;
41 #endif
42
43 void yaz_init_globals(void)
44 {
45     if (yaz_init_flag)
46         return;
47 #if YAZ_POSIX_THREADS
48     pthread_mutex_lock(&yaz_init_mutex);
49 #endif
50     if (!yaz_init_flag)
51     {
52         yaz_log_init_globals();
53 #if HAVE_GCRYPT_H
54         /* POSIX threads locking. In case gnutls_global_init do not override */
55         gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
56 #endif
57 #if HAVE_GNUTLS_H
58         gnutls_global_init();
59 #endif
60 #if HAVE_GCRYPT_H
61         /* most likely, GnuTLS has already initialized libgcrypt */
62         if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
63         {
64             gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
65         }
66 #endif
67 #if YAZ_HAVE_EXSLT
68         exsltRegisterAll();
69 #endif
70         yaz_init_flag = 1; /* must be last, before unlocking */
71     }
72 #if YAZ_POSIX_THREADS
73     pthread_mutex_unlock(&yaz_init_mutex);
74 #endif
75 }
76
77 /*
78  * Local variables:
79  * c-basic-offset: 4
80  * c-file-style: "Stroustrup"
81  * indent-tabs-mode: nil
82  * End:
83  * vim: shiftwidth=4 tabstop=8 expandtab
84  */
85