aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrfree2monero <rfreemonero@op.pl>2015-02-24 21:02:48 +0100
committerrfree2monero <rfreemonero@op.pl>2015-02-24 21:06:02 +0100
commitf79821ac7ebc269b18dd2edd8ac0cb022861ad11 (patch)
treee7e1d625b0b1bfb2a6b9aea73f5a8115b55fca5e
parent2014 network limit 1.3 fix log/path/data +utils (diff)
downloadmonero-f79821ac7ebc269b18dd2edd8ac0cb022861ad11.tar.xz
fix locking in count-peers thread (2)
Diffstat (limited to '')
-rw-r--r--src/daemon/daemon.cpp2
-rw-r--r--src/p2p/data_logger.cpp8
-rw-r--r--src/p2p/net_node.h11
-rw-r--r--src/p2p/net_node.inl19
4 files changed, 28 insertions, 12 deletions
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 8d584af5e..4a93a0db8 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -320,7 +320,7 @@ int main(int argc, char* argv[])
ccore.set_cryptonote_protocol(NULL);
cprotocol.set_p2p_endpoint(NULL);
- epee::net_utils::data_logger::get_instance().kill_instance();
+ epee::net_utils::data_logger::kill_instance();
LOG_PRINT("Node stopped.", LOG_LEVEL_0);
return 0;
diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp
index d62af133e..69e50141a 100644
--- a/src/p2p/data_logger.cpp
+++ b/src/p2p/data_logger.cpp
@@ -20,6 +20,12 @@ namespace net_utils
m_state = data_logger_state::state_ready_to_use;
}
);
+
+ if (m_state != data_logger_state::state_ready_to_use) {
+ _erro ("trying to use not working data_logger");
+ throw std::runtime_error("data_logger ctor state");
+ }
+
return * m_obj;
}
@@ -82,7 +88,7 @@ namespace net_utils
}
void data_logger::kill_instance() {
- m_state = m_state = data_logger_state::state_dying;
+ m_state = data_logger_state::state_dying;
m_obj.reset();
}
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 5417ffa52..5b034ce25 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -89,6 +89,7 @@ namespace nodetool
{
m_current_number_of_out_peers = 0;
m_save_graph = false;
+ is_closing = false;
}
static void init_options(boost::program_options::options_description& desc);
@@ -209,6 +210,13 @@ namespace nodetool
bool set_rate_down_limit(const boost::program_options::variables_map& vm, int64_t limit);
bool set_rate_limit(const boost::program_options::variables_map& vm, uint64_t limit);
+ void kill() { ///< will be called e.g. from deinit()
+ _info("Killing the net_node");
+ is_closing = true;
+ mPeersLoggerThread->join(); // make sure the thread finishes
+ _info("Joined extra background net_node threads");
+ }
+
//debug functions
std::string print_connections_container();
@@ -247,7 +255,8 @@ namespace nodetool
bool m_hide_my_port;
bool m_no_igd;
std::atomic<bool> m_save_graph;
-
+ std::atomic<bool> is_closing;
+ std::unique_ptr<std::thread> 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 a015763bf..afc6436f3 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -291,17 +291,17 @@ namespace nodetool
std::vector<std::vector<std::string>> dns_results;
dns_results.resize(m_seed_nodes_list.size());
- std::shared_ptr<std::thread> peersLoggerThread (new std::thread([&]()
+ // creating thread to log number of connections
+ mPeersLoggerThread.reset(new std::thread([&]()
{
- unsigned int number_of_peers;
- while (1)
- {
+ _note("Thread monitor number of peers - start");
+ while (!is_closing)
+ { // main loop of thread
//number_of_peers = m_net_server.get_config_object().get_connections_count();
- number_of_peers = 0;
+ unsigned int number_of_peers = 0;
m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt)
{
- if(!cntxt.m_is_income)
- ++number_of_peers;
+ if (!cntxt.m_is_income) ++number_of_peers;
return true;
}); // lambda
@@ -309,10 +309,10 @@ namespace nodetool
epee::net_utils::data_logger::get_instance().add_data("peers", number_of_peers);
std::this_thread::sleep_for(std::chrono::seconds(1));
- }
+ } // main loop of thread
+ _note("Thread monitor number of peers - done");
})); // lambda
- peersLoggerThread->detach();
std::list<boost::thread*> dns_threads;
uint64_t result_index = 0;
@@ -509,6 +509,7 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::deinit()
{
+ kill();
m_peerlist.deinit();
m_net_server.deinit_server();