From 62dcf640c8fe44c3723d0279acfc15b77c1d880c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 5 Dec 2017 16:06:03 +0100
Subject: [PATCH] proxy_client: use atomic bool for shared state flags

---
 include/opendht/dht_proxy_client.h |  2 +-
 src/dht_proxy_client.cpp           | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h
index c6dbf835..adeff410 100644
--- a/include/opendht/dht_proxy_client.h
+++ b/include/opendht/dht_proxy_client.h
@@ -282,7 +282,7 @@ private:
     {
         std::shared_ptr<restbed::Request> req;
         std::thread thread;
-        std::shared_ptr<bool> finished;
+        std::shared_ptr<std::atomic_bool> finished;
     };
     std::vector<Operation> operations_;
     std::mutex lockOperations_;
diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp
index d93f32bd..ad9e585a 100644
--- a/src/dht_proxy_client.cpp
+++ b/src/dht_proxy_client.cpp
@@ -192,14 +192,14 @@ DhtProxyClient::get(const InfoHash& key, GetCallback cb, DoneCallback donecb,
     Query query {{}, where};
     auto filterChain = filter.chain(query.where.getFilter());
 
-    auto finished = std::make_shared<bool>(false);
+    auto finished = std::make_shared<std::atomic_bool>(false);
     Operation o;
     o.req = req;
     o.finished = finished;
     o.thread = std::thread([=](){
         // Try to contact the proxy and set the status to connected when done.
         // will change the connectivity status
-        auto ok = std::make_shared<bool>(true);
+        auto ok = std::make_shared<std::atomic_bool>(true);
         restbed::Http::async(req,
             [=](const std::shared_ptr<restbed::Request>& req,
                 const std::shared_ptr<restbed::Response>& reply) {
@@ -267,12 +267,12 @@ DhtProxyClient::put(const InfoHash& key, Sp<Value> val, DoneCallback cb, time_po
     req->set_body(body);
     req->set_header("Content-Length", std::to_string(body.size()));
 
-    auto finished = std::make_shared<bool>(false);
+    auto finished = std::make_shared<std::atomic_bool>(false);
     Operation o;
     o.req = req;
     o.finished = finished;
     o.thread = std::thread([=](){
-        auto ok = std::make_shared<bool>(true);
+        auto ok = std::make_shared<std::atomic_bool>(true);
         restbed::Http::async(req,
             [this, ok](const std::shared_ptr<restbed::Request>& /*req*/,
                         const std::shared_ptr<restbed::Response>& reply) {
@@ -426,8 +426,8 @@ DhtProxyClient::listen(const InfoHash& key, GetCallback cb, Value::Filter&& filt
             settings->set_connection_timeout(timeout); // Avoid the client to close the socket after 5 seconds.
 
             struct State {
-                bool ok {true};
-                bool cancel {false};
+                std::atomic_bool ok {true};
+                std::atomic_bool cancel {false};
             };
             auto state = std::make_shared<State>();
             restbed::Http::async(req,
-- 
GitLab