]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
gcrypt: Use predefined pthread locking functions instead of custom hooks
authorMartin Willi <martin@revosec.ch>
Tue, 1 Jul 2014 08:33:25 +0000 (10:33 +0200)
committerMartin Willi <martin@revosec.ch>
Tue, 1 Jul 2014 10:23:19 +0000 (12:23 +0200)
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.

src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c

index 44f3f84b1d5632f4af73e52d6744e994c8d59ad0..f4254bb938c24c62a3fee771a9f160e84041d97d 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <errno.h>
 #include <gcrypt.h>
+#include <pthread.h>
 
 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;
 }
-