From 4e7c4c2f1b44cf575866a737b5df157b05adcc95 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 26 Aug 2014 17:56:34 +0000 Subject: fixed gcrypt thread support --- src/cryptinit.hpp | 44 ++++++++++---------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) (limited to 'src') 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