From 3f44dbd1d2924f001c45793e706a6217aa8aa471 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 19 Oct 2008 23:53:47 +0000 Subject: the signal controller uses boost thread now, however this code can only work as long boost thread uses pthread removed temporarly brocken anyrtpproxy from all target at make use make anyrtpproxy to build it replaced the pthread callbacks for libgcrypt with boost thread callbacks --- src/anytun.cpp | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'src/anytun.cpp') diff --git a/src/anytun.cpp b/src/anytun.cpp index 5bd3214..f01ef4f 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include // for ENOMEM @@ -325,21 +326,52 @@ void receiver(void* p) } } -#define MIN_GCRYPT_VERSION "1.2.0" -#if defined(__GNUC__) && !defined(__OpenBSD__) // TODO: thread-safety on OpenBSD -// make libgcrypt thread safe -extern "C" { -GCRY_THREAD_OPTION_PTHREAD_IMPL; +// boost thread callbacks for libgcrypt + +typedef boost::detail::thread::lock_ops mutex_ops; + +static int boost_mutex_init(void **priv) +{ + int err = 0; + boost::mutex *lock = new boost::mutex(); + + if (!lock) + err = ENOMEM; + if (!err) + *priv = lock; + return err; +} + +static int boost_mutex_destroy(void **lock) +{ + delete reinterpret_cast(*lock); + return 0; } -#endif + +static int boost_mutex_lock(void **lock) +{ + mutex_ops::lock(*reinterpret_cast(*lock)); + return 0; +} + +static int boost_mutex_unlock(void **lock) +{ + mutex_ops::unlock(*reinterpret_cast(*lock)); + 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 }; + +#define MIN_GCRYPT_VERSION "1.2.0" bool initLibGCrypt() { // make libgcrypt thread safe // this must be called before any other libgcrypt call -#if defined(__GNUC__) && !defined(__OpenBSD__) // TODO: thread-safety on OpenBSD - gcry_control( GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread ); -#endif + gcry_control( GCRYCTL_SET_THREAD_CBS, &gcry_threads_boost ); // this must be called right after the GCRYCTL_SET_THREAD_CBS command // no other function must be called till now -- cgit v1.2.3