Skip to content
Snippets Groups Projects
Commit 6e523104 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

dhtrunnner: properly lock mutex in run & join

parent 77750543
Branches
Tags
No related merge requests found
...@@ -110,6 +110,7 @@ DhtRunner::run(const SockAddr& local4, const SockAddr& local6, const Config& con ...@@ -110,6 +110,7 @@ DhtRunner::run(const SockAddr& local4, const SockAddr& local6, const Config& con
void void
DhtRunner::run(const Config& config, Context&& context) DhtRunner::run(const Config& config, Context&& context)
{ {
std::lock_guard<std::mutex> lck(dht_mtx);
if (running) if (running)
return; return;
...@@ -230,12 +231,14 @@ DhtRunner::shutdown(ShutdownCallback cb) { ...@@ -230,12 +231,14 @@ DhtRunner::shutdown(ShutdownCallback cb) {
void void
DhtRunner::join() DhtRunner::join()
{ {
if (peerDiscovery_)
peerDiscovery_->stop();
{
std::lock_guard<std::mutex> lck(dht_mtx);
running = false; running = false;
cv.notify_all(); cv.notify_all();
bootstrap_cv.notify_all(); bootstrap_cv.notify_all();
if (peerDiscovery_) peerDiscovery_->stop();
{
std::lock_guard<std::mutex> lck(dht_mtx);
if (dht_) if (dht_)
if (auto sock = dht_->getSocket()) if (auto sock = dht_->getSocket())
sock->stop(); sock->stop();
...@@ -243,6 +246,7 @@ DhtRunner::join() ...@@ -243,6 +246,7 @@ DhtRunner::join()
if (dht_thread.joinable()) if (dht_thread.joinable())
dht_thread.join(); dht_thread.join();
if (bootstrap_thread.joinable()) if (bootstrap_thread.joinable())
bootstrap_thread.join(); bootstrap_thread.join();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment