X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fglib-util.c;h=9fd8ced967bae8b91086e4c752a751523834c371;hb=c4f19a4c1ce2b200d4e18c880257a4389bd5368c;hp=91985e500f4efa670c7ee69116af001ae4761a65;hpb=cb38d19aa8dc2c5d380ab2d7ad9724a5d99eee5d;p=debian%2Famanda diff --git a/common-src/glib-util.c b/common-src/glib-util.c index 91985e5..9fd8ced 100644 --- a/common-src/glib-util.c +++ b/common-src/glib-util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published @@ -30,7 +30,64 @@ #ifdef HAVE_LIBCURL #include -#endif + +#ifdef LIBCURL_USE_OPENSSL +#include +static GMutex **openssl_mutex_array; +static void openssl_lock_callback(int mode, int type, const char *file, int line) +{ + (void)file; + (void)line; + if (mode & CRYPTO_LOCK) { + g_mutex_lock(openssl_mutex_array[type]); + } + else { + g_mutex_unlock(openssl_mutex_array[type]); + } +} + +static void +init_ssl(void) +{ + int i; + + openssl_mutex_array = g_new0(GMutex *, CRYPTO_num_locks()); + + for (i=0; i +#include + +GCRY_THREAD_OPTION_PTHREAD_IMPL; +static void +init_ssl(void) +{ + gcry_control(GCRYCTL_SET_THREAD_CBS); +} + +#else /* LIBCURL_USE_GNUTLS */ + +static void +init_ssl(void) +{ +} +#endif /* LIBCURL_USE_GNUTLS */ +#endif /* LIBCURL_USE_OPENSSL */ + +#else /* HAVE_LIBCURL */ +static void +init_ssl(void) +{ +} +#endif /* HAVE_LIBCURL */ void glib_init(void) { @@ -42,7 +99,9 @@ glib_init(void) { * is initialized) */ #ifdef HAVE_LIBCURL # ifdef G_THREADS_ENABLED +# if (GLIB_MAJOR_VERSION < 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 31)) g_assert(!g_thread_supported()); /* assert threads aren't initialized yet */ +# endif # endif g_assert(curl_global_init(CURL_GLOBAL_ALL) == 0); #endif @@ -70,6 +129,10 @@ glib_init(void) { if (!g_thread_supported()) g_thread_init(NULL); #endif + + /* initialize ssl */ + init_ssl(); + } typedef enum { @@ -120,15 +183,6 @@ void slist_free_full(GSList * list, GDestroyNotify free_fn) { } #endif -void g_queue_free_full(GQueue * queue) { - while (!g_queue_is_empty(queue)) { - gpointer data; - data = g_queue_pop_head(queue); - amfree(data); - } - g_queue_free(queue); -} - void g_ptr_array_free_full(GPtrArray * array) { size_t i;