aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
authorHoward Chu <hyc@symas.com>2016-03-11 12:25:28 +0000
committerHoward Chu <hyc@symas.com>2016-03-11 15:09:50 +0000
commitb937a2c915861900d047d4d4a24af31c454e3540 (patch)
treeceedf9b256b9769f72cb34319e4144ae127543dc /src/p2p
parentMerge pull request #705 (diff)
downloadmonero-b937a2c915861900d047d4d4a24af31c454e3540.tar.xz
Use boost::thread instead of std::thread
and all other associated IPC
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/data_logger.cpp18
-rw-r--r--src/p2p/data_logger.hpp9
-rw-r--r--src/p2p/net_node.inl2
-rw-r--r--src/p2p/network_throttle-detail.cpp2
-rw-r--r--src/p2p/network_throttle.cpp18
-rw-r--r--src/p2p/network_throttle.hpp12
6 files changed, 31 insertions, 30 deletions
diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp
index 7fc85e3bc..ca0726c5f 100644
--- a/src/p2p/data_logger.cpp
+++ b/src/p2p/data_logger.cpp
@@ -40,7 +40,7 @@ namespace epee
namespace net_utils
{
data_logger &data_logger::get_instance() {
- std::call_once(m_singleton,
+ boost::call_once(m_singleton,
[] {
_info_c("dbg/data","Creating singleton of data_logger");
if (m_state != data_logger_state::state_before_init) { _erro_c("dbg/data","Internal error in singleton"); throw std::runtime_error("data_logger singleton"); }
@@ -61,7 +61,7 @@ namespace net_utils
data_logger::data_logger() {
_note_c("dbg/data","Starting data logger (for graphs data)");
if (m_state != data_logger_state::state_during_init) { _erro_c("dbg/data","Singleton ctor state"); throw std::runtime_error("data_logger ctor state"); }
- std::lock_guard<std::mutex> lock(mMutex); // lock
+ boost::lock_guard<boost::mutex> lock(mMutex); // lock
// prepare all the files for given data channels:
mFilesMap["peers"] = data_logger::fileData("log/dr-monero/peers.data");
@@ -89,11 +89,11 @@ namespace net_utils
std::shared_ptr<boost::thread> 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));
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
}
_info_c("dbg/data","Inside thread for data logger - going into main loop");
while (m_state == data_logger_state::state_ready_to_use) { // run as long as we are not closing the single object
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
saveToFile(); // save all the pending data
}
_info_c("dbg/data","Inside thread for data logger - done the main loop");
@@ -106,12 +106,12 @@ namespace net_utils
data_logger::~data_logger() {
_note_c("dbg/data","Destructor of the data logger");
{
- std::lock_guard<std::mutex> lock(mMutex);
+ boost::lock_guard<boost::mutex> lock(mMutex);
m_state = data_logger_state::state_dying;
}
_info_c("dbg/data","State was set to dying");
while(m_thread_maybe_running) { // wait for the thread to exit
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
_info_c("dbg/data","Waiting for background thread to exit");
}
_info_c("dbg/data","Thread exited");
@@ -123,7 +123,7 @@ namespace net_utils
}
void data_logger::add_data(std::string filename, unsigned int data) {
- std::lock_guard<std::mutex> lock(mMutex);
+ boost::lock_guard<boost::mutex> lock(mMutex);
if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; }
if (mFilesMap.find(filename) == mFilesMap.end()) { // no such file/counter
@@ -151,7 +151,7 @@ namespace net_utils
void data_logger::saveToFile() {
_dbg2_c("dbg/data","saving to files");
- std::lock_guard<std::mutex> lock(mMutex);
+ boost::lock_guard<boost::mutex> lock(mMutex);
if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; }
nOT::nUtils::cFilesystemUtils::CreateDirTree("log/dr-monero/net/");
for (auto &element : mFilesMap)
@@ -194,7 +194,7 @@ namespace net_utils
data_logger_state data_logger::m_state(data_logger_state::state_before_init); ///< (static) state of the singleton object
std::atomic<bool> data_logger::m_save_graph(false); // (static)
std::atomic<bool> data_logger::m_thread_maybe_running(false); // (static)
-std::once_flag data_logger::m_singleton; // (static)
+boost::once_flag data_logger::m_singleton; // (static)
std::unique_ptr<data_logger> data_logger::m_obj; // (static)
} // namespace
diff --git a/src/p2p/data_logger.hpp b/src/p2p/data_logger.hpp
index affc97f5f..148afc0ab 100644
--- a/src/p2p/data_logger.hpp
+++ b/src/p2p/data_logger.hpp
@@ -33,8 +33,9 @@
#include <map>
#include <fstream>
#include <memory>
-#include <thread>
-#include <mutex>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/once.hpp>
#include <atomic>
namespace epee
@@ -71,7 +72,7 @@ enum class data_logger_state { state_before_init, state_during_init, state_ready
static bool is_dying();
private:
- static std::once_flag m_singleton; ///< to guarantee singleton creates the object exactly once
+ static boost::once_flag m_singleton; ///< to guarantee singleton creates the object exactly once
static data_logger_state m_state; ///< state of the singleton object
static std::atomic<bool> m_thread_maybe_running; ///< is the background thread (more or less) running, or is it fully finished
static std::unique_ptr<data_logger> m_obj; ///< the singleton object. Only use it via get_instance(). Can be killed by kill_instance()
@@ -94,7 +95,7 @@ enum class data_logger_state { state_before_init, state_during_init, state_ready
};
std::map<std::string, fileData> mFilesMap;
- std::mutex mMutex;
+ boost::mutex mMutex;
void saveToFile(); ///< write data to the target files. do not use this directly
};
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 56717ec66..6278db891 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -585,7 +585,7 @@ namespace nodetool
break;
epee::net_utils::data_logger::get_instance().add_data("peers", number_of_peers);
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
} // main loop of thread
_note("Thread monitor number of peers - done");
})); // lambda
diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp
index 54c82dd8d..ed3c8e7b4 100644
--- a/src/p2p/network_throttle-detail.cpp
+++ b/src/p2p/network_throttle-detail.cpp
@@ -243,7 +243,7 @@ network_time_seconds network_throttle::get_sleep_time_after_tick(size_t packet_s
void network_throttle::logger_handle_net(const std::string &filename, double time, size_t size) {
if (! epee::net_utils::data_logger::m_save_graph)
return;
- std::mutex mutex;
+ boost::mutex mutex;
mutex.lock(); {
std::fstream file;
file.open(filename.c_str(), std::ios::app | std::ios::out );
diff --git a/src/p2p/network_throttle.cpp b/src/p2p/network_throttle.cpp
index 42f54964b..30538bb3c 100644
--- a/src/p2p/network_throttle.cpp
+++ b/src/p2p/network_throttle.cpp
@@ -67,9 +67,9 @@ namespace net_utils
// ================================================================================================
// static:
-std::mutex network_throttle_manager::m_lock_get_global_throttle_in;
-std::mutex network_throttle_manager::m_lock_get_global_throttle_inreq;
-std::mutex network_throttle_manager::m_lock_get_global_throttle_out;
+boost::mutex network_throttle_manager::m_lock_get_global_throttle_in;
+boost::mutex network_throttle_manager::m_lock_get_global_throttle_inreq;
+boost::mutex network_throttle_manager::m_lock_get_global_throttle_out;
int network_throttle_manager::xxx;
@@ -77,27 +77,27 @@ int network_throttle_manager::xxx;
// ================================================================================================
// methods:
i_network_throttle & network_throttle_manager::get_global_throttle_in() {
- std::call_once(m_once_get_global_throttle_in, [] { m_obj_get_global_throttle_in.reset(new network_throttle("in/all","<<< global-IN",10)); } );
+ boost::call_once(m_once_get_global_throttle_in, [] { m_obj_get_global_throttle_in.reset(new network_throttle("in/all","<<< global-IN",10)); } );
return * m_obj_get_global_throttle_in;
}
-std::once_flag network_throttle_manager::m_once_get_global_throttle_in;
+boost::once_flag network_throttle_manager::m_once_get_global_throttle_in;
std::unique_ptr<i_network_throttle> network_throttle_manager::m_obj_get_global_throttle_in;
i_network_throttle & network_throttle_manager::get_global_throttle_inreq() {
- std::call_once(m_once_get_global_throttle_inreq, [] { m_obj_get_global_throttle_inreq.reset(new network_throttle("inreq/all", "<== global-IN-REQ",10)); } );
+ boost::call_once(m_once_get_global_throttle_inreq, [] { m_obj_get_global_throttle_inreq.reset(new network_throttle("inreq/all", "<== global-IN-REQ",10)); } );
return * m_obj_get_global_throttle_inreq;
}
-std::once_flag network_throttle_manager::m_once_get_global_throttle_inreq;
+boost::once_flag network_throttle_manager::m_once_get_global_throttle_inreq;
std::unique_ptr<i_network_throttle> network_throttle_manager::m_obj_get_global_throttle_inreq;
i_network_throttle & network_throttle_manager::get_global_throttle_out() {
- std::call_once(m_once_get_global_throttle_out, [] { m_obj_get_global_throttle_out.reset(new network_throttle("out/all", ">>> global-OUT",10)); } );
+ boost::call_once(m_once_get_global_throttle_out, [] { m_obj_get_global_throttle_out.reset(new network_throttle("out/all", ">>> global-OUT",10)); } );
return * m_obj_get_global_throttle_out;
}
-std::once_flag network_throttle_manager::m_once_get_global_throttle_out;
+boost::once_flag network_throttle_manager::m_once_get_global_throttle_out;
std::unique_ptr<i_network_throttle> network_throttle_manager::m_obj_get_global_throttle_out;
diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp
index 6135ed72b..b954c5b3a 100644
--- a/src/p2p/network_throttle.hpp
+++ b/src/p2p/network_throttle.hpp
@@ -113,16 +113,16 @@ class network_throttle_manager {
//protected:
public: // XXX
// [[note1]]
- static std::once_flag m_once_get_global_throttle_in;
- static std::once_flag m_once_get_global_throttle_inreq; // [[note2]]
- static std::once_flag m_once_get_global_throttle_out;
+ static boost::once_flag m_once_get_global_throttle_in;
+ static boost::once_flag m_once_get_global_throttle_inreq; // [[note2]]
+ static boost::once_flag m_once_get_global_throttle_out;
static std::unique_ptr<i_network_throttle> m_obj_get_global_throttle_in;
static std::unique_ptr<i_network_throttle> m_obj_get_global_throttle_inreq;
static std::unique_ptr<i_network_throttle> m_obj_get_global_throttle_out;
- static std::mutex m_lock_get_global_throttle_in;
- static std::mutex m_lock_get_global_throttle_inreq;
- static std::mutex m_lock_get_global_throttle_out;
+ static boost::mutex m_lock_get_global_throttle_in;
+ static boost::mutex m_lock_get_global_throttle_inreq;
+ static boost::mutex m_lock_get_global_throttle_out;
friend class cryptonote::cryptonote_protocol_handler_base; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS!
friend class connection_basic; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS!