From: Martin Willi Date: Tue, 1 Jul 2014 08:33:25 +0000 (+0200) Subject: gcrypt: Use predefined pthread locking functions instead of custom hooks X-Git-Tag: 5.2.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fb12832420ad7f2c4a999f356e336bb7a6be9f6;p=thirdparty%2Fstrongswan.git gcrypt: Use predefined pthread locking functions instead of custom hooks Starting with libgcrypt 1.6, it seems that custom locking functions are not supported anymore. Instead, the user has to select from one of the pre-defined set of locking functions. Given that we have a proper threading abstraction API with optional profiling on all platforms, this is somewhat annoying. However, there does not seem to be a way to use custom functions, and we have no other choice than using the provided macro magic to support all libgcrypt versions. Fixes #630. --- diff --git a/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c b/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c index 44f3f84b1d..f4254bb938 100644 --- a/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c +++ b/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c @@ -28,6 +28,7 @@ #include #include +#include typedef struct private_gcrypt_plugin_t private_gcrypt_plugin_t; @@ -43,55 +44,9 @@ struct private_gcrypt_plugin_t { }; /** - * gcrypt mutex initialization wrapper + * Define gcrypt multi-threading callbacks as gcry_threads_pthread */ -static int mutex_init(void **lock) -{ - *lock = mutex_create(MUTEX_TYPE_DEFAULT); - return 0; -} - -/** - * gcrypt mutex cleanup wrapper - */ -static int mutex_destroy(void **lock) -{ - mutex_t *mutex = *lock; - - mutex->destroy(mutex); - return 0; -} - -/** - * gcrypt mutex lock wrapper - */ -static int mutex_lock(void **lock) -{ - mutex_t *mutex = *lock; - - mutex->lock(mutex); - return 0; -} - -/** - * gcrypt mutex unlock wrapper - */ -static int mutex_unlock(void **lock) -{ - mutex_t *mutex = *lock; - - mutex->unlock(mutex); - return 0; -} - -/** - * gcrypt locking functions using our mutex_t - */ -static struct gcry_thread_cbs thread_functions = { - GCRY_THREAD_OPTION_USER, NULL, - mutex_init, mutex_destroy, mutex_lock, mutex_unlock, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL -}; +GCRY_THREAD_OPTION_PTHREAD_IMPL; METHOD(plugin_t, get_name, char*, private_gcrypt_plugin_t *this) @@ -184,7 +139,7 @@ plugin_t *gcrypt_plugin_create() { private_gcrypt_plugin_t *this; - gcry_control(GCRYCTL_SET_THREAD_CBS, &thread_functions); + gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); if (!gcry_check_version(GCRYPT_VERSION)) { @@ -213,4 +168,3 @@ plugin_t *gcrypt_plugin_create() return &this->public.plugin; } -