From: Adam Dickmeiss Date: Mon, 24 Feb 2014 12:01:05 +0000 (+0100) Subject: Thread safe yaz_init_globals X-Git-Tag: v5.0.15~1 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=becf0d3294d52943303c8b3646f99260912c6f4b;p=yaz-moved-to-github.git Thread safe yaz_init_globals --- diff --git a/src/init_globals.c b/src/init_globals.c index 81301e2..1f2905c 100644 --- a/src/init_globals.c +++ b/src/init_globals.c @@ -25,26 +25,37 @@ #endif static int yaz_init_flag = 0; +#if YAZ_POSIX_THREADS +static pthread_mutex_t yaz_init_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif extern void yaz_log_init_globals(void); void yaz_init_globals(void) { + if (yaz_init_flag) + return; +#if YAZ_POSIX_THREADS + pthread_mutex_lock(&yaz_init_mutex); +#endif if (!yaz_init_flag) { - yaz_init_flag = 1; yaz_log_init_globals(); #if HAVE_GNUTLS_H gnutls_global_init(); #endif #if HAVE_GCRYPT_H - /* most likely, GnuTLS has initialized libgcrypt */ + /* most likely, GnuTLS has already initialized libgcrypt */ if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) { gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0); } #endif + yaz_init_flag = 1; } +#if YAZ_POSIX_THREADS + pthread_mutex_unlock(&yaz_init_mutex); +#endif } /*