From 7c86c5997d72062191c2fb4fbaf003bf48485842 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 18 Feb 2016 21:30:10 +0000 Subject: [PATCH 1/3] Use boost::thread instead of std::thread std::thread crashes on (at least) ARMv6 g++ 4.8/4.9 --- contrib/epee/include/console_handler.h | 5 +++-- src/p2p/data_logger.cpp | 3 ++- src/p2p/net_node.h | 2 +- src/p2p/net_node.inl | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index 5c63556ae..d76d7930c 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -36,6 +36,7 @@ #ifdef __OpenBSD__ #include #endif +#include namespace epee { @@ -47,7 +48,7 @@ namespace epee , m_has_read_request(false) , m_read_status(state_init) { - m_reader_thread = std::thread(std::bind(&async_stdin_reader::reader_thread_func, this)); + m_reader_thread = boost::thread(std::bind(&async_stdin_reader::reader_thread_func, this)); } ~async_stdin_reader() @@ -212,7 +213,7 @@ namespace epee }; private: - std::thread m_reader_thread; + boost::thread m_reader_thread; std::atomic m_run; std::string m_line; diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp index f875cb8f0..7fc85e3bc 100644 --- a/src/p2p/data_logger.cpp +++ b/src/p2p/data_logger.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include "../../contrib/otshell_utils/utils.hpp" @@ -85,7 +86,7 @@ namespace net_utils _info_c("dbg/data","Creating thread for data logger"); // create timer thread m_thread_maybe_running=true; - std::shared_ptr logger_thread(new std::thread([&]() { + std::shared_ptr logger_thread(new boost::thread([&]() { _info_c("dbg/data","Inside thread for data logger"); while (m_state == data_logger_state::state_during_init) { // wait for creation to be done (in other thread, in singleton) before actually running std::this_thread::sleep_for(std::chrono::seconds(1)); diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 2ae849e2a..260dd813d 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -270,7 +270,7 @@ namespace nodetool bool m_offline; std::atomic m_save_graph; std::atomic is_closing; - std::unique_ptr mPeersLoggerThread; + std::unique_ptr mPeersLoggerThread; //critical_section m_connections_lock; //connections_indexed_container m_connections; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 47a5dc6c3..56717ec66 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -567,7 +567,7 @@ namespace nodetool bool node_server::run() { // creating thread to log number of connections - mPeersLoggerThread.reset(new std::thread([&]() + mPeersLoggerThread.reset(new boost::thread([&]() { _note("Thread monitor number of peers - start"); while (!is_closing && !m_net_server.is_stop_signal_sent()) From 014f8868f215175fc8db41f79d57588db9ea1d4d Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 26 Jan 2016 22:09:08 +0000 Subject: [PATCH 2/3] std::condvar is broken on Win32 with gcc/g++ 4.8 too Use boost... --- contrib/epee/include/syncobj.h | 10 ++++------ src/common/dns_utils.cpp | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h index b81eb43a9..275324436 100644 --- a/contrib/epee/include/syncobj.h +++ b/contrib/epee/include/syncobj.h @@ -30,8 +30,6 @@ #ifndef __WINH_OBJ_H__ #define __WINH_OBJ_H__ -#include -#include #include #include #include @@ -51,22 +49,22 @@ namespace epee void raise() { - std::unique_lock lock(m_mx); + boost::unique_lock lock(m_mx); m_rised = true; m_cond_var.notify_one(); } void wait() { - std::unique_lock lock(m_mx); + boost::unique_lock lock(m_mx); while (!m_rised) m_cond_var.wait(lock); m_rised = false; } private: - std::mutex m_mx; - std::condition_variable m_cond_var; + boost::mutex m_mx; + boost::condition_variable m_cond_var; bool m_rised; }; diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index eb7b6608b..eb0a7de1f 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -38,7 +38,7 @@ using namespace epee; namespace bf = boost::filesystem; -static std::mutex instance_lock; +static boost::mutex instance_lock; namespace { @@ -304,7 +304,7 @@ std::string DNSResolver::get_dns_format_from_oa_address(const std::string& oa_ad DNSResolver& DNSResolver::instance() { - std::lock_guard lock(instance_lock); + boost::lock_guard lock(instance_lock); static DNSResolver* staticInstance = NULL; if (staticInstance == NULL) From 11d555cebe70053479f8c7ce8a8a993821b634b9 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 27 Jan 2016 14:07:14 +0000 Subject: [PATCH 3/3] Fix crash in std::map for connections_map Use boost::unordered_map instead. --- contrib/epee/include/net/levin_protocol_handler_async.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index a7fbffb4b..7331faa35 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include #include @@ -52,7 +53,7 @@ class async_protocol_handler; template class async_protocol_handler_config { - typedef std::map* > connections_map; + typedef boost::unordered_map* > connections_map; critical_section m_connects_lock; connections_map m_connects;