From 40d1dc1883f9dabafa1dbcecf01dbc7b01f890e0 Mon Sep 17 00:00:00 2001 From: BtbN Date: Wed, 30 Jul 2014 00:55:08 +0200 Subject: [PATCH 1/2] Initialize OpenSSL locking functions --- src/main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ac9d691f..02fcf897 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,63 @@ #include #include +#if defined(HAVE_LIBSSL) && defined(HAVE_PTHREAD) +#include +#include +#include + +static std::vector > lock_cs; + +static void locking_callback(int mode, int type, const char *file, int line) { + if(mode & CRYPTO_LOCK) { + lock_cs[type]->lock(); + } else { + lock_cs[type]->unlock(); + } +} + +static unsigned long thread_id_callback() { + return (unsigned long)pthread_self(); +} + +static CRYPTO_dynlock_value *dyn_create_callback(const char *file, int line) { + return (CRYPTO_dynlock_value*)new CMutex; +} + +static void dyn_lock_callback(int mode, CRYPTO_dynlock_value *dlock, const char *file, int line) { + CMutex *mtx = (CMutex*)dlock; + + if(mode & CRYPTO_LOCK) { + mtx->lock(); + } else { + mtx->unlock(); + } +} + +static void dyn_destroy_callback(CRYPTO_dynlock_value *dlock, const char *file, int line) { + CMutex *mtx = (CMutex*)dlock; + + delete mtx; +} + +static void thread_setup() { + lock_cs.resize(CRYPTO_num_locks()); + + for(std::unique_ptr &mtx: lock_cs) + mtx = std::unique_ptr(new CMutex()); + + CRYPTO_set_id_callback(&thread_id_callback); + CRYPTO_set_locking_callback(&locking_callback); + + CRYPTO_set_dynlock_create_callback(&dyn_create_callback); + CRYPTO_set_dynlock_lock_callback(&dyn_lock_callback); + CRYPTO_set_dynlock_destroy_callback(&dyn_destroy_callback); +} + +#else +#define thread_setup() +#endif + using std::cout; using std::endl; using std::set; @@ -126,6 +183,8 @@ int main(int argc, char** argv) { CString sConfig; CString sDataDir = ""; + thread_setup(); + seedPRNG(); CDebug::SetStdoutIsTTY(isatty(1)); From 7b7d10fd84338eda5e84d166347c613c6e886948 Mon Sep 17 00:00:00 2001 From: BtbN Date: Fri, 5 Sep 2014 23:56:41 +0200 Subject: [PATCH 2/2] Remove _GLIBCXX_CONCEPT_CHECKS debug define This debug feature does not support any C++11 features. It breaks for example the compilation of vector. The upstream issue is: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57011 --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index 752169e7..b2bbf515 100644 --- a/configure.ac +++ b/configure.ac @@ -203,7 +203,6 @@ if test "$DEBUG" != "no"; then # But they cause crashes on cygwin while loading modules AC_DEFINE([_GLIBCXX_DEBUG], [1], [Enable extra debugging checks in libstdc++]) AC_DEFINE([_GLIBCXX_DEBUG_PEDANTIC], [1], [Enable extra debugging checks in libstdc++]) - AC_DEFINE([_GLIBCXX_CONCEPT_CHECKS], [1], [Enable extra debugging checks in libstdc++]) fi else if test "x$OPTIMIZE" = "xyes"; then