From 9c87c6c11e2f2b7667f23d5b6f852c997e5b203e Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Sat, 12 Oct 2019 13:07:48 +0200 Subject: [PATCH] [880-some-improvements-for-threadsanitizer] Added some atomics to satisfy the thread sanitizer --- src/bin/netconf/netconf_process.cc | 2 +- src/bin/netconf/netconf_process.h | 5 +++-- src/bin/netconf/tests/netconf_unittests.cc | 5 +++-- src/bin/perfdhcp/receiver.h | 5 +++-- src/lib/asiolink/interval_timer.cc | 8 +++++--- src/lib/process/d_process.h | 4 +++- src/lib/util/tests/watched_thread_unittest.cc | 3 ++- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/bin/netconf/netconf_process.cc b/src/bin/netconf/netconf_process.cc index 228450e6b2..30f085cc92 100644 --- a/src/bin/netconf/netconf_process.cc +++ b/src/bin/netconf/netconf_process.cc @@ -26,7 +26,7 @@ using namespace isc::process; namespace isc { namespace netconf { -bool NetconfProcess::shut_down = false; +std::atomic NetconfProcess::shut_down(false); NetconfProcess::NetconfProcess(const char* name, const asiolink::IOServicePtr& io_service) diff --git a/src/bin/netconf/netconf_process.h b/src/bin/netconf/netconf_process.h index 9bdc7e8826..35f6811819 100644 --- a/src/bin/netconf/netconf_process.h +++ b/src/bin/netconf/netconf_process.h @@ -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 #include #include +#include namespace isc { namespace netconf { @@ -85,7 +86,7 @@ public: NetconfCfgMgrPtr getNetconfCfgMgr(); /// @brief Global (globally visible) shutdown flag. - static bool shut_down; + static std::atomic shut_down; private: diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc index b5a9e876dc..c3bf4814d0 100644 --- a/src/bin/netconf/tests/netconf_unittests.cc +++ b/src/bin/netconf/tests/netconf_unittests.cc @@ -24,6 +24,7 @@ #include #include #include +#include using namespace std; using namespace isc; @@ -425,10 +426,10 @@ public: } // To know when the callback was called. - static bool finished; + static atomic finished; }; -bool TestCallback::finished = false; +atomic TestCallback::finished(false); /// Verifies the logChanges method handles correctly changes. TEST_F(NetconfAgentLogTest, logChanges) { diff --git a/src/bin/perfdhcp/receiver.h b/src/bin/perfdhcp/receiver.h index 504b53ce51..13ce6ce0db 100644 --- a/src/bin/perfdhcp/receiver.h +++ b/src/bin/perfdhcp/receiver.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include 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 recv_thread_; @@ -62,6 +62,7 @@ public: socket_(socket), single_threaded_(single_threaded), ip_version_(ip_version) { + run_flag_.clear(); } /// \brief Destructor. diff --git a/src/lib/asiolink/interval_timer.cc b/src/lib/asiolink/interval_timer.cc index 808cd5990d..b579e9581d 100644 --- a/src/lib/asiolink/interval_timer.cc +++ b/src/lib/asiolink/interval_timer.cc @@ -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 +#include + 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 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, diff --git a/src/lib/process/d_process.h b/src/lib/process/d_process.h index f5de80c46a..335ca60cbe 100644 --- a/src/lib/process/d_process.h +++ b/src/lib/process/d_process.h @@ -15,6 +15,8 @@ #include +#include + 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 shut_down_flag_; /// @brief Pointer to the configuration manager. DCfgMgrBasePtr cfg_mgr_; diff --git a/src/lib/util/tests/watched_thread_unittest.cc b/src/lib/util/tests/watched_thread_unittest.cc index 25cd9ca4c9..0ace4d875d 100644 --- a/src/lib/util/tests/watched_thread_unittest.cc +++ b/src/lib/util/tests/watched_thread_unittest.cc @@ -12,6 +12,7 @@ #include #include +#include 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 passes_; }; const int WatchedThreadTest::WORKER_MAX_PASSES = 10; -- 2.47.2