Merge pull request #678

11d555c Fix crash in std::map for connections_map (Howard Chu)
014f886 std::condvar is broken on Win32 with gcc/g++ 4.8 too (Howard Chu)
7c86c59 Use boost::thread instead of std::thread (Howard Chu)
This commit is contained in:
Riccardo Spagni 2016-02-20 17:10:51 +02:00
commit c3baa82ac8
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
7 changed files with 15 additions and 14 deletions

View file

@ -36,6 +36,7 @@
#ifdef __OpenBSD__ #ifdef __OpenBSD__
#include <stdio.h> #include <stdio.h>
#endif #endif
#include <boost/thread.hpp>
namespace epee namespace epee
{ {
@ -47,7 +48,7 @@ namespace epee
, m_has_read_request(false) , m_has_read_request(false)
, m_read_status(state_init) , 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() ~async_stdin_reader()
@ -212,7 +213,7 @@ namespace epee
}; };
private: private:
std::thread m_reader_thread; boost::thread m_reader_thread;
std::atomic<bool> m_run; std::atomic<bool> m_run;
std::string m_line; std::string m_line;

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_generators.hpp>
#include <boost/unordered_map.hpp>
#include <boost/interprocess/detail/atomic.hpp> #include <boost/interprocess/detail/atomic.hpp>
#include <boost/smart_ptr/make_shared.hpp> #include <boost/smart_ptr/make_shared.hpp>
@ -52,7 +53,7 @@ class async_protocol_handler;
template<class t_connection_context> template<class t_connection_context>
class async_protocol_handler_config class async_protocol_handler_config
{ {
typedef std::map<boost::uuids::uuid, async_protocol_handler<t_connection_context>* > connections_map; typedef boost::unordered_map<boost::uuids::uuid, async_protocol_handler<t_connection_context>* > connections_map;
critical_section m_connects_lock; critical_section m_connects_lock;
connections_map m_connects; connections_map m_connects;

View file

@ -30,8 +30,6 @@
#ifndef __WINH_OBJ_H__ #ifndef __WINH_OBJ_H__
#define __WINH_OBJ_H__ #define __WINH_OBJ_H__
#include <condition_variable>
#include <mutex>
#include <boost/thread/locks.hpp> #include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp> #include <boost/thread/recursive_mutex.hpp>
@ -51,22 +49,22 @@ namespace epee
void raise() void raise()
{ {
std::unique_lock<std::mutex> lock(m_mx); boost::unique_lock<boost::mutex> lock(m_mx);
m_rised = true; m_rised = true;
m_cond_var.notify_one(); m_cond_var.notify_one();
} }
void wait() void wait()
{ {
std::unique_lock<std::mutex> lock(m_mx); boost::unique_lock<boost::mutex> lock(m_mx);
while (!m_rised) while (!m_rised)
m_cond_var.wait(lock); m_cond_var.wait(lock);
m_rised = false; m_rised = false;
} }
private: private:
std::mutex m_mx; boost::mutex m_mx;
std::condition_variable m_cond_var; boost::condition_variable m_cond_var;
bool m_rised; bool m_rised;
}; };

View file

@ -38,7 +38,7 @@
using namespace epee; using namespace epee;
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
static std::mutex instance_lock; static boost::mutex instance_lock;
namespace namespace
{ {
@ -304,7 +304,7 @@ std::string DNSResolver::get_dns_format_from_oa_address(const std::string& oa_ad
DNSResolver& DNSResolver::instance() DNSResolver& DNSResolver::instance()
{ {
std::lock_guard<std::mutex> lock(instance_lock); boost::lock_guard<boost::mutex> lock(instance_lock);
static DNSResolver* staticInstance = NULL; static DNSResolver* staticInstance = NULL;
if (staticInstance == NULL) if (staticInstance == NULL)

View file

@ -31,6 +31,7 @@
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/thread.hpp>
#include <chrono> #include <chrono>
#include "../../contrib/otshell_utils/utils.hpp" #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 _info_c("dbg/data","Creating thread for data logger"); // create timer thread
m_thread_maybe_running=true; m_thread_maybe_running=true;
std::shared_ptr<std::thread> logger_thread(new std::thread([&]() { std::shared_ptr<boost::thread> logger_thread(new boost::thread([&]() {
_info_c("dbg/data","Inside thread for data logger"); _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 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)); std::this_thread::sleep_for(std::chrono::seconds(1));

View file

@ -270,7 +270,7 @@ namespace nodetool
bool m_offline; bool m_offline;
std::atomic<bool> m_save_graph; std::atomic<bool> m_save_graph;
std::atomic<bool> is_closing; std::atomic<bool> is_closing;
std::unique_ptr<std::thread> mPeersLoggerThread; std::unique_ptr<boost::thread> mPeersLoggerThread;
//critical_section m_connections_lock; //critical_section m_connections_lock;
//connections_indexed_container m_connections; //connections_indexed_container m_connections;

View file

@ -567,7 +567,7 @@ namespace nodetool
bool node_server<t_payload_net_handler>::run() bool node_server<t_payload_net_handler>::run()
{ {
// creating thread to log number of connections // creating thread to log number of connections
mPeersLoggerThread.reset(new std::thread([&]() mPeersLoggerThread.reset(new boost::thread([&]()
{ {
_note("Thread monitor number of peers - start"); _note("Thread monitor number of peers - start");
while (!is_closing && !m_net_server.is_stop_signal_sent()) while (!is_closing && !m_net_server.is_stop_signal_sent())