From b855d2ba95a877ed4db7a3833b2416682d308a0e Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Thu, 25 Sep 2014 16:28:17 +0000 Subject: merged gcrypt threading fixes --- ChangeLog | 3 ++- src/cryptinit.hpp | 44 ++++++++++---------------------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a89c6e..284ae2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2014.??.?? -- Version 0.3.5 +2014.08.26 -- Version 0.3.5 * added an exception to the license which allows linking with OpenSSL * added support for clang * added libnettle as additional crypto library option +* fixed mutli-threading support for libgcrypt 1.6.0 and newer 2011.12.30 -- Version 0.3.4 diff --git a/src/cryptinit.hpp b/src/cryptinit.hpp index 090e9e8..cd11215 100644 --- a/src/cryptinit.hpp +++ b/src/cryptinit.hpp @@ -51,48 +51,24 @@ #if defined(USE_GCRYPT) #include +#if defined(BOOST_HAS_PTHREADS) // boost thread callbacks for libgcrypt -static int boost_mutex_init(void** priv) -{ - boost::mutex* lock = new boost::mutex(); - if(!lock) { - return ENOMEM; - } - *priv = lock; - return 0; -} - -static int boost_mutex_destroy(void** lock) -{ - delete reinterpret_cast(*lock); - return 0; -} - -static int boost_mutex_lock(void** lock) -{ - reinterpret_cast(*lock)->lock(); - return 0; -} - -static int boost_mutex_unlock(void** lock) -{ - reinterpret_cast(*lock)->unlock(); - return 0; -} - -static struct gcry_thread_cbs gcry_threads_boost = { - GCRY_THREAD_OPTION_USER, NULL, - boost_mutex_init, boost_mutex_destroy, - boost_mutex_lock, boost_mutex_unlock -}; +GCRY_THREAD_OPTION_PTHREAD_IMPL; +#else +#error You can not use gcrypt without pthreads - please configure Boost to use pthreads! +#endif #define MIN_GCRYPT_VERSION "1.2.0" bool initLibGCrypt() { +#if defined(BOOST_HAS_PTHREADS) // make libgcrypt thread safe // this must be called before any other libgcrypt call - gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_boost); + gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); +#else +#error You can not use gcrypt without pthreads - please configure Boost to use pthreads! +#endif // this must be called right after the GCRYCTL_SET_THREAD_CBS command // no other function must be called till now -- cgit v1.2.3