]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[880-some-improvements-for-threadsanitizer] Added some atomics to satisfy the thread... 880-some-improvements-for-threadsanitizer
authorFrancis Dupont <fdupont@isc.org>
Sat, 12 Oct 2019 11:07:48 +0000 (13:07 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sat, 12 Oct 2019 11:07:48 +0000 (13:07 +0200)
src/bin/netconf/netconf_process.cc
src/bin/netconf/netconf_process.h
src/bin/netconf/tests/netconf_unittests.cc
src/bin/perfdhcp/receiver.h
src/lib/asiolink/interval_timer.cc
src/lib/process/d_process.h
src/lib/util/tests/watched_thread_unittest.cc

index 228450e6b25633bc2e57d5755988796c74d7e496..30f085cc9280071a201c526d64cd5bf4cbc20e35 100644 (file)
@@ -26,7 +26,7 @@ using namespace isc::process;
 namespace isc {
 namespace netconf {
 
-bool NetconfProcess::shut_down = false;
+std::atomic<bool> NetconfProcess::shut_down(false);
 
 NetconfProcess::NetconfProcess(const char* name,
                                const asiolink::IOServicePtr& io_service)
index 9bdc7e8826b5be02f9d5461d4637eafdd1ea021a..35f68118198e02c0bc50d55af08a9a076a7ee1a2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -10,6 +10,7 @@
 #include <netconf/netconf.h>
 #include <process/d_process.h>
 #include <vector>
+#include <atomic>
 
 namespace isc {
 namespace netconf {
@@ -85,7 +86,7 @@ public:
     NetconfCfgMgrPtr getNetconfCfgMgr();
 
     /// @brief Global (globally visible) shutdown flag.
-    static bool shut_down;
+    static std::atomic<bool> shut_down;
 
 private:
 
index b5a9e876dc431335d2e47a2bca87c47a0292e85a..c3bf4814d019adffd2ba9ea9250c654bbfedece5 100644 (file)
@@ -24,6 +24,7 @@
 #include <gtest/gtest.h>
 #include <sstream>
 #include <thread>
+#include <atomic>
 
 using namespace std;
 using namespace isc;
@@ -425,10 +426,10 @@ public:
     }
 
     // To know when the callback was called.
-    static bool finished;
+    static atomic<bool> finished;
 };
 
-bool TestCallback::finished = false;
+atomic<bool> TestCallback::finished(false);
 
 /// Verifies the logChanges method handles correctly changes.
 TEST_F(NetconfAgentLogTest, logChanges) {
index 504b53ce51b163ae8b92f037f43f0159d688847a..13ce6ce0dba294c358608cacc895d9fef698ab0d 100644 (file)
@@ -15,7 +15,7 @@
 #include <queue>
 #include <thread>
 #include <mutex>
-#include <boost/atomic.hpp>
+#include <atomic>
 
 namespace isc {
 namespace perfdhcp {
@@ -34,7 +34,7 @@ namespace perfdhcp {
 class Receiver {
 private:
     /// \brief Flag indicating if thread should run (true) or not (false).
-    boost::atomic_flag run_flag_;
+    std::atomic_flag run_flag_;
 
     /// \brief Thread for receiving packets.
     std::unique_ptr<std::thread> recv_thread_;
@@ -62,6 +62,7 @@ public:
         socket_(socket),
         single_threaded_(single_threaded),
         ip_version_(ip_version) {
+        run_flag_.clear();
     }
 
     /// \brief Destructor.
index 808cd5990da11b9ce56b13b8b1044f3fc6dba4c5..b579e9581d911480744e61aa52b066d6cccd573d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2019 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -15,6 +15,8 @@
 
 #include <exceptions/exceptions.h>
 
+#include <atomic>
+
 namespace isc {
 namespace asiolink {
 
@@ -50,7 +52,7 @@ private:
     // a function to call back when timer_ expires
     IntervalTimer::Callback cbfunc_;
     // interval in milliseconds
-    long interval_;
+    std::atomic<long> interval_;
     // asio timer
     boost::asio::deadline_timer timer_;
 
@@ -99,7 +101,7 @@ void
 IntervalTimerImpl::update() {
     try {
         // Update expire time to (current time + interval_).
-        timer_.expires_from_now(boost::posix_time::millisec(interval_));
+        timer_.expires_from_now(boost::posix_time::millisec(long(interval_)));
         // Reset timer.
         // Pass a function bound with a shared_ptr to this.
         timer_.async_wait(boost::bind(&IntervalTimerImpl::callback,
index f5de80c46a308d2ebe2d7aa10d2b77b3d0f948c8..335ca60cbe0b3f6bf550fc9900a349cb611d5503 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <exceptions/exceptions.h>
 
+#include <atomic>
+
 namespace isc {
 namespace process {
 
@@ -200,7 +202,7 @@ private:
     asiolink::IOServicePtr io_service_;
 
     /// @brief Boolean flag set when shutdown has been requested.
-    bool shut_down_flag_;
+    std::atomic<bool> shut_down_flag_;
 
     /// @brief  Pointer to the configuration manager.
     DCfgMgrBasePtr cfg_mgr_;
index 25cd9ca4c9e9f512619128873bf76f94a22a025a..0ace4d875ddc2a74d03017c0496f29c71d2bd44f 100644 (file)
@@ -12,6 +12,7 @@
 #include <gtest/gtest.h>
 
 #include <unistd.h>
+#include <atomic>
 
 using namespace std;
 using namespace isc;
@@ -84,7 +85,7 @@ public:
 
     /// @brief Counter used to track the number of passes made
     /// within the thread worker function.
-    int passes_;
+    std::atomic<int> passes_;
 };
 
 const int WatchedThreadTest::WORKER_MAX_PASSES = 10;