aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-06-04 17:15:35 +0200
committerMartin Willi <martin@strongswan.org>2009-06-09 11:18:56 +0200
commit8e97e32705de41d50260fc6ee6d86efd4201606e (patch)
tree2190ebcd249b3b8d20f241dfaefbb3b5c736db05 /src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c
parent80862c463719ac73bbb0e8bd17f5348d3f07dafb (diff)
downloadstrongswan-8e97e32705de41d50260fc6ee6d86efd4201606e.tar.bz2
strongswan-8e97e32705de41d50260fc6ee6d86efd4201606e.tar.xz
use abstract mutex_t for gcrypt locking callbacks
Diffstat (limited to 'src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c')
-rw-r--r--src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c b/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c
index 5568de8d4..4f66e3421 100644
--- a/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c
+++ b/src/libstrongswan/plugins/gcrypt/gcrypt_plugin.c
@@ -20,10 +20,10 @@
#include <library.h>
#include <debug.h>
+#include <utils/mutex.h>
#include <errno.h>
#include <gcrypt.h>
-#include <pthread.h>
typedef struct private_gcrypt_plugin_t private_gcrypt_plugin_t;
@@ -39,9 +39,55 @@ struct private_gcrypt_plugin_t {
};
/**
- * Thread callback implementations for pthread
+ * gcrypt mutex initialization wrapper
*/
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
+static int mutex_init(void **lock)
+{
+ *lock = mutex_create(MUTEX_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
+};
/**
* Implementation of gcrypt_plugin_t.destroy
@@ -62,7 +108,7 @@ plugin_t *plugin_create()
{
private_gcrypt_plugin_t *this;
- gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+ gcry_control(GCRYCTL_SET_THREAD_CBS, &thread_functions);
if (!gcry_check_version(GCRYPT_VERSION))
{