From 7d7eaa8dd35c23ed8de9112343ece3b5b7bdbd73 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 12:12:58 +0100 Subject: [PATCH] Replace boost::thread with std::thread --- icinga-app/icinga.cpp | 3 ++- lib/base/application.cpp | 5 +++-- lib/base/process.cpp | 3 ++- lib/base/socketevents-poll.cpp | 2 +- lib/base/socketevents.cpp | 4 ++-- lib/base/socketevents.hpp | 4 ++-- lib/base/threadpool.cpp | 2 +- lib/base/threadpool.hpp | 3 ++- lib/base/timer.cpp | 6 +++--- lib/base/utility.cpp | 3 ++- lib/checker/checkercomponent.cpp | 2 +- lib/checker/checkercomponent.hpp | 4 ++-- lib/compat/externalcommandlistener.cpp | 2 +- lib/compat/externalcommandlistener.hpp | 4 ++-- lib/compat/statusdatawriter.hpp | 1 - lib/livestatus/livestatuslistener.cpp | 4 ++-- lib/livestatus/livestatuslistener.hpp | 4 ++-- lib/remote/apilistener.cpp | 6 +++--- lib/remote/eventqueue.hpp | 1 - 19 files changed, 33 insertions(+), 30 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index f5665c983..a0d75293c 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -35,6 +35,7 @@ #include "config.h" #include #include +#include #ifndef _WIN32 # include @@ -159,7 +160,7 @@ int Main(void) Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses()); Application::DeclareRLimitStack(Application::GetDefaultRLimitStack()); #endif /* __linux__ */ - Application::DeclareConcurrency(boost::thread::hardware_concurrency()); + Application::DeclareConcurrency(std::thread::hardware_concurrency()); ScriptGlobal::Set("AttachDebugger", false); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 43a69e893..23847c03b 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifdef __linux__ #include #endif /* __linux__ */ @@ -394,7 +395,7 @@ static void ReloadProcessCallback(const ProcessResult& pr) { l_Restarting = false; - boost::thread t(std::bind(&ReloadProcessCallbackInternal, pr)); + std::thread t(std::bind(&ReloadProcessCallbackInternal, pr)); t.detach(); } @@ -1508,7 +1509,7 @@ void Application::DeclareConcurrency(int ncpus) */ int Application::GetConcurrency(void) { - Value defaultConcurrency = boost::thread::hardware_concurrency(); + Value defaultConcurrency = std::thread::hardware_concurrency(); return ScriptGlobal::Get("Concurrency", &defaultConcurrency); } diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 3d0cd5d3e..a8f354088 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -30,6 +30,7 @@ #include "base/json.hpp" #include #include +#include #include #ifndef _WIN32 @@ -539,7 +540,7 @@ void Process::ThreadInitialize(void) { /* Note to self: Make sure this runs _after_ we've daemonized. */ for (int tid = 0; tid < IOTHREADS; tid++) { - boost::thread t(std::bind(&Process::IOThreadProc, tid)); + std::thread t(std::bind(&Process::IOThreadProc, tid)); t.detach(); } } diff --git a/lib/base/socketevents-poll.cpp b/lib/base/socketevents-poll.cpp index 76c13cfc6..d141abe95 100644 --- a/lib/base/socketevents-poll.cpp +++ b/lib/base/socketevents-poll.cpp @@ -192,7 +192,7 @@ void SocketEventEnginePoll::ChangeEvents(SocketEvents *se, int events) it->second.Events = events; - if (se->m_EnginePrivate && boost::this_thread::get_id() == m_Threads[tid].get_id()) + if (se->m_EnginePrivate && std::this_thread::get_id() == m_Threads[tid].get_id()) ((pollfd *)se->m_EnginePrivate)->events = events; else m_FDChanged[tid] = true; diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp index 00ca0c525..8b77da1a0 100644 --- a/lib/base/socketevents.cpp +++ b/lib/base/socketevents.cpp @@ -50,7 +50,7 @@ void SocketEventEngine::Start(void) InitializeThread(tid); - m_Threads[tid] = boost::thread(std::bind(&SocketEventEngine::ThreadProc, this, tid)); + m_Threads[tid] = std::thread(std::bind(&SocketEventEngine::ThreadProc, this, tid)); } } @@ -58,7 +58,7 @@ void SocketEventEngine::WakeUpThread(int sid, bool wait) { int tid = sid % SOCKET_IOTHREADS; - if (boost::this_thread::get_id() == m_Threads[tid].get_id()) + if (std::this_thread::get_id() == m_Threads[tid].get_id()) return; if (wait) { diff --git a/lib/base/socketevents.hpp b/lib/base/socketevents.hpp index b659cc321..c40d36430 100644 --- a/lib/base/socketevents.hpp +++ b/lib/base/socketevents.hpp @@ -22,7 +22,7 @@ #include "base/i2-base.hpp" #include "base/socket.hpp" -#include +#include #ifndef _WIN32 # include @@ -109,7 +109,7 @@ protected: virtual void Unregister(SocketEvents *se) = 0; virtual void ChangeEvents(SocketEvents *se, int events) = 0; - boost::thread m_Threads[SOCKET_IOTHREADS]; + std::thread m_Threads[SOCKET_IOTHREADS]; SOCKET m_EventFDs[SOCKET_IOTHREADS][2]; bool m_FDChanged[SOCKET_IOTHREADS]; boost::mutex m_EventMutex[SOCKET_IOTHREADS]; diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 0c2925f9b..df5152d60 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -54,7 +54,7 @@ void ThreadPool::Start(void) for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++) m_Queues[i].SpawnWorker(m_ThreadGroup); - m_MgmtThread = boost::thread(std::bind(&ThreadPool::ManagerThreadProc, this)); + m_MgmtThread = std::thread(std::bind(&ThreadPool::ManagerThreadProc, this)); } void ThreadPool::Stop(void) diff --git a/lib/base/threadpool.hpp b/lib/base/threadpool.hpp index d37ca8366..d49ffa414 100644 --- a/lib/base/threadpool.hpp +++ b/lib/base/threadpool.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace icinga { @@ -121,7 +122,7 @@ private: boost::thread_group m_ThreadGroup; - boost::thread m_MgmtThread; + std::thread m_MgmtThread; boost::mutex m_MgmtMutex; boost::condition_variable m_MgmtCV; bool m_Stopped; diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 9c1a2c4a1..3e6099da9 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -20,12 +20,12 @@ #include "base/timer.hpp" #include "base/debug.hpp" #include "base/utility.hpp" -#include #include #include #include #include #include +#include using namespace icinga; @@ -39,7 +39,7 @@ typedef boost::multi_index_container< static boost::mutex l_TimerMutex; static boost::condition_variable l_TimerCV; -static boost::thread l_TimerThread; +static std::thread l_TimerThread; static bool l_StopTimerThread; static TimerSet l_Timers; @@ -65,7 +65,7 @@ void Timer::Initialize(void) { boost::mutex::scoped_lock lock(l_TimerMutex); l_StopTimerThread = false; - l_TimerThread = boost::thread(&Timer::TimerThreadProc); + l_TimerThread = std::thread(&Timer::TimerThreadProc); } /** diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index d98aebbfb..02238f712 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -28,6 +28,7 @@ #include "base/objectlock.hpp" #include #include +#include #include #include #include @@ -1221,7 +1222,7 @@ String Utility::GetThreadName(void) if (!name) { std::ostringstream idbuf; - idbuf << boost::this_thread::get_id(); + idbuf << std::this_thread::get_id(); return idbuf.str(); } diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index a943872b9..406bca10b 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -79,7 +79,7 @@ void CheckerComponent::Start(bool runtimeCreated) << "'" << GetName() << "' started."; - m_Thread = boost::thread(std::bind(&CheckerComponent::CheckThreadProc, this)); + m_Thread = std::thread(std::bind(&CheckerComponent::CheckThreadProc, this)); m_ResultTimer = new Timer(); m_ResultTimer->SetInterval(5); diff --git a/lib/checker/checkercomponent.hpp b/lib/checker/checkercomponent.hpp index 988d3d180..2459e8958 100644 --- a/lib/checker/checkercomponent.hpp +++ b/lib/checker/checkercomponent.hpp @@ -25,12 +25,12 @@ #include "base/configobject.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include #include #include #include #include #include +#include namespace icinga { @@ -91,7 +91,7 @@ private: boost::mutex m_Mutex; boost::condition_variable m_CV; bool m_Stopped; - boost::thread m_Thread; + std::thread m_Thread; CheckableSet m_IdleCheckables; CheckableSet m_PendingCheckables; diff --git a/lib/compat/externalcommandlistener.cpp b/lib/compat/externalcommandlistener.cpp index 040255160..b426f3563 100644 --- a/lib/compat/externalcommandlistener.cpp +++ b/lib/compat/externalcommandlistener.cpp @@ -54,7 +54,7 @@ void ExternalCommandListener::Start(bool runtimeCreated) << "'" << GetName() << "' started."; #ifndef _WIN32 - m_CommandThread = boost::thread(std::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath())); + m_CommandThread = std::thread(std::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath())); m_CommandThread.detach(); #endif /* _WIN32 */ } diff --git a/lib/compat/externalcommandlistener.hpp b/lib/compat/externalcommandlistener.hpp index 02df0ded3..b40a1c940 100644 --- a/lib/compat/externalcommandlistener.hpp +++ b/lib/compat/externalcommandlistener.hpp @@ -24,7 +24,7 @@ #include "base/objectlock.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include +#include #include namespace icinga @@ -47,7 +47,7 @@ protected: private: #ifndef _WIN32 - boost::thread m_CommandThread; + std::thread m_CommandThread; void CommandPipeThread(const String& commandPath); #endif /* _WIN32 */ diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index 3a0460fd3..4b4e234d5 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -28,7 +28,6 @@ #include "icinga/compatutility.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include #include namespace icinga diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index ae0cbc1e6..3fc7391ed 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -82,7 +82,7 @@ void LivestatusListener::Start(bool runtimeCreated) m_Listener = socket; - m_Thread = boost::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); + m_Thread = std::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); Log(LogInformation, "LivestatusListener") << "Created TCP socket listening on host '" << GetBindHost() << "' port '" << GetBindPort() << "'."; @@ -110,7 +110,7 @@ void LivestatusListener::Start(bool runtimeCreated) m_Listener = socket; - m_Thread = boost::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); + m_Thread = std::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); Log(LogInformation, "LivestatusListener") << "Created UNIX socket in '" << GetSocketPath() << "'."; diff --git a/lib/livestatus/livestatuslistener.hpp b/lib/livestatus/livestatuslistener.hpp index 56be37c05..6f23f6040 100644 --- a/lib/livestatus/livestatuslistener.hpp +++ b/lib/livestatus/livestatuslistener.hpp @@ -24,7 +24,7 @@ #include "livestatus/livestatuslistener.thpp" #include "livestatus/livestatusquery.hpp" #include "base/socket.hpp" -#include +#include using namespace icinga; @@ -56,7 +56,7 @@ private: void ClientHandler(const Socket::Ptr& client); Socket::Ptr m_Listener; - boost::thread m_Thread; + std::thread m_Thread; }; } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 60c75210d..b64b3c3dd 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -332,7 +332,7 @@ bool ApiListener::AddListener(const String& node, const String& service) return false; } - boost::thread thread(std::bind(&ApiListener::ListenerThreadProc, this, server)); + std::thread thread(std::bind(&ApiListener::ListenerThreadProc, this, server)); thread.detach(); m_Servers.insert(server); @@ -349,7 +349,7 @@ void ApiListener::ListenerThreadProc(const Socket::Ptr& server) for (;;) { try { Socket::Ptr client = server->Accept(); - boost::thread thread(std::bind(&ApiListener::NewClientHandler, this, client, String(), RoleServer)); + std::thread thread(std::bind(&ApiListener::NewClientHandler, this, client, String(), RoleServer)); thread.detach(); } catch (const std::exception&) { Log(LogCritical, "ApiListener", "Cannot accept new connection."); @@ -744,7 +744,7 @@ void ApiListener::ApiReconnectTimerHandler(void) continue; } - boost::thread thread(std::bind(&ApiListener::AddConnection, this, endpoint)); + std::thread thread(std::bind(&ApiListener::AddConnection, this, endpoint)); thread.detach(); } } diff --git a/lib/remote/eventqueue.hpp b/lib/remote/eventqueue.hpp index a9e66ee13..893fd8efe 100644 --- a/lib/remote/eventqueue.hpp +++ b/lib/remote/eventqueue.hpp @@ -23,7 +23,6 @@ #include "remote/httphandler.hpp" #include "base/object.hpp" #include "config/expression.hpp" -#include #include #include #include