Commit 5f9937b1 authored by Francis Dupont's avatar Francis Dupont

[#880] Added some atomics to satisfy the thread sanitizer

parent de4cd27f
...@@ -26,7 +26,7 @@ using namespace isc::process; ...@@ -26,7 +26,7 @@ using namespace isc::process;
namespace isc { namespace isc {
namespace netconf { namespace netconf {
bool NetconfProcess::shut_down = false; std::atomic<bool> NetconfProcess::shut_down(false);
NetconfProcess::NetconfProcess(const char* name, NetconfProcess::NetconfProcess(const char* name,
const asiolink::IOServicePtr& io_service) const asiolink::IOServicePtr& io_service)
......
// 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 // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <netconf/netconf.h> #include <netconf/netconf.h>
#include <process/d_process.h> #include <process/d_process.h>
#include <vector> #include <vector>
#include <atomic>
namespace isc { namespace isc {
namespace netconf { namespace netconf {
...@@ -85,7 +86,7 @@ public: ...@@ -85,7 +86,7 @@ public:
NetconfCfgMgrPtr getNetconfCfgMgr(); NetconfCfgMgrPtr getNetconfCfgMgr();
/// @brief Global (globally visible) shutdown flag. /// @brief Global (globally visible) shutdown flag.
static bool shut_down; static std::atomic<bool> shut_down;
private: private:
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <atomic>
using namespace std; using namespace std;
using namespace isc; using namespace isc;
...@@ -425,10 +426,10 @@ public: ...@@ -425,10 +426,10 @@ public:
} }
// To know when the callback was called. // 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. /// Verifies the logChanges method handles correctly changes.
TEST_F(NetconfAgentLogTest, logChanges) { TEST_F(NetconfAgentLogTest, logChanges) {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <queue> #include <queue>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <boost/atomic.hpp> #include <atomic>
namespace isc { namespace isc {
namespace perfdhcp { namespace perfdhcp {
...@@ -34,7 +34,7 @@ namespace perfdhcp { ...@@ -34,7 +34,7 @@ namespace perfdhcp {
class Receiver { class Receiver {
private: private:
/// \brief Flag indicating if thread should run (true) or not (false). /// \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. /// \brief Thread for receiving packets.
std::unique_ptr<std::thread> recv_thread_; std::unique_ptr<std::thread> recv_thread_;
...@@ -62,6 +62,7 @@ public: ...@@ -62,6 +62,7 @@ public:
socket_(socket), socket_(socket),
single_threaded_(single_threaded), single_threaded_(single_threaded),
ip_version_(ip_version) { ip_version_(ip_version) {
run_flag_.clear();
} }
/// \brief Destructor. /// \brief Destructor.
......
// 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 // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <exceptions/exceptions.h> #include <exceptions/exceptions.h>
#include <atomic>
namespace isc { namespace isc {
namespace asiolink { namespace asiolink {
...@@ -50,7 +52,7 @@ private: ...@@ -50,7 +52,7 @@ private:
// a function to call back when timer_ expires // a function to call back when timer_ expires
IntervalTimer::Callback cbfunc_; IntervalTimer::Callback cbfunc_;
// interval in milliseconds // interval in milliseconds
long interval_; std::atomic<long> interval_;
// asio timer // asio timer
boost::asio::deadline_timer timer_; boost::asio::deadline_timer timer_;
...@@ -99,7 +101,7 @@ void ...@@ -99,7 +101,7 @@ void
IntervalTimerImpl::update() { IntervalTimerImpl::update() {
try { try {
// Update expire time to (current time + interval_). // 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. // Reset timer.
// Pass a function bound with a shared_ptr to this. // Pass a function bound with a shared_ptr to this.
timer_.async_wait(boost::bind(&IntervalTimerImpl::callback, timer_.async_wait(boost::bind(&IntervalTimerImpl::callback,
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <exceptions/exceptions.h> #include <exceptions/exceptions.h>
#include <atomic>
namespace isc { namespace isc {
namespace process { namespace process {
...@@ -203,7 +205,7 @@ private: ...@@ -203,7 +205,7 @@ private:
asiolink::IOServicePtr io_service_; asiolink::IOServicePtr io_service_;
/// @brief Boolean flag set when shutdown has been requested. /// @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. /// @brief Pointer to the configuration manager.
DCfgMgrBasePtr cfg_mgr_; DCfgMgrBasePtr cfg_mgr_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <unistd.h> #include <unistd.h>
#include <atomic>
using namespace std; using namespace std;
using namespace isc; using namespace isc;
...@@ -84,7 +85,7 @@ public: ...@@ -84,7 +85,7 @@ public:
/// @brief Counter used to track the number of passes made /// @brief Counter used to track the number of passes made
/// within the thread worker function. /// within the thread worker function.
int passes_; std::atomic<int> passes_;
}; };
const int WatchedThreadTest::WORKER_MAX_PASSES = 10; const int WatchedThreadTest::WORKER_MAX_PASSES = 10;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment