From c3388e9af69a6a598730a65c2ae74173f2e7fc74 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 2 Feb 2021 10:16:04 +0100 Subject: [PATCH] Use std::mutex, not boost::mutex --- lib/base/configtype.cpp | 10 +++---- lib/base/configtype.hpp | 4 +-- lib/base/configwriter.cpp | 8 +++--- lib/base/dependencygraph.cpp | 8 +++--- lib/base/dependencygraph.hpp | 4 +-- lib/base/logger.cpp | 8 +++--- lib/base/logger.hpp | 2 +- lib/base/object.cpp | 8 +++--- lib/base/process.cpp | 16 +++++------ lib/base/registry.hpp | 20 ++++++------- lib/base/ringbuffer.cpp | 8 +++--- lib/base/ringbuffer.hpp | 4 +-- lib/base/singleton.hpp | 1 - lib/base/socket.cpp | 4 +-- lib/base/socket.hpp | 4 +-- lib/base/stream.cpp | 16 +++++------ lib/base/stream.hpp | 8 +++--- lib/base/streamlogger.cpp | 4 +-- lib/base/streamlogger.hpp | 2 +- lib/base/timer.cpp | 37 +++++++++++++------------ lib/base/tlsutility.cpp | 8 +++--- lib/base/workqueue.cpp | 20 ++++++------- lib/base/workqueue.hpp | 16 +++++------ lib/checker/checkercomponent.cpp | 19 +++++++------ lib/checker/checkercomponent.hpp | 8 +++--- lib/cli/clicommand.cpp | 14 +++++----- lib/cli/clicommand.hpp | 2 +- lib/cli/consolecommand.cpp | 4 +-- lib/cli/consolecommand.hpp | 5 ++-- lib/config/configcompiler.cpp | 6 ++-- lib/config/configcompiler.hpp | 2 +- lib/config/configcompilercontext.cpp | 2 +- lib/config/configcompilercontext.hpp | 4 +-- lib/config/configitem.cpp | 28 +++++++++---------- lib/config/configitem.hpp | 2 +- lib/db_ido/dbconnection.cpp | 4 +-- lib/db_ido/dbconnection.hpp | 4 +-- lib/db_ido/dbobject.cpp | 6 ++-- lib/db_ido/dbobject.hpp | 2 +- lib/db_ido/dbtype.cpp | 12 ++++---- lib/db_ido/dbtype.hpp | 2 +- lib/icinga/checkable-check.cpp | 12 ++++---- lib/icinga/checkable-comment.cpp | 6 ++-- lib/icinga/checkable-dependency.cpp | 12 ++++---- lib/icinga/checkable-downtime.cpp | 6 ++-- lib/icinga/checkable-notification.cpp | 6 ++-- lib/icinga/checkable.cpp | 2 +- lib/icinga/checkable.hpp | 15 +++++----- lib/icinga/cib.hpp | 2 +- lib/icinga/clusterevents-check.cpp | 6 ++-- lib/icinga/clusterevents.hpp | 2 +- lib/icinga/comment.cpp | 8 +++--- lib/icinga/downtime.cpp | 8 +++--- lib/icinga/externalcommandprocessor.cpp | 8 +++--- lib/icinga/externalcommandprocessor.hpp | 2 +- lib/icinga/host.cpp | 8 +++--- lib/icinga/host.hpp | 2 +- lib/icinga/hostgroup.cpp | 6 ++-- lib/icinga/hostgroup.hpp | 2 +- lib/icinga/servicegroup.cpp | 6 ++-- lib/icinga/servicegroup.hpp | 2 +- lib/icinga/user.cpp | 2 +- lib/icinga/user.hpp | 2 +- lib/icinga/usergroup.cpp | 6 ++-- lib/icinga/usergroup.hpp | 2 +- lib/livestatus/livestatuslistener.cpp | 10 +++---- lib/livestatus/livestatusquery.cpp | 6 ++-- lib/livestatus/logtable.hpp | 1 - lib/livestatus/statehisttable.hpp | 1 - lib/perfdata/elasticsearchwriter.cpp | 4 +-- lib/perfdata/elasticsearchwriter.hpp | 2 +- lib/perfdata/graphitewriter.cpp | 2 +- lib/perfdata/graphitewriter.hpp | 4 +-- lib/perfdata/perfdatawriter.cpp | 6 ++-- lib/perfdata/perfdatawriter.hpp | 2 +- lib/remote/apilistener.cpp | 30 ++++++++++---------- lib/remote/apilistener.hpp | 8 +++--- lib/remote/configobjectutility.cpp | 2 +- lib/remote/configpackageshandler.cpp | 4 +-- lib/remote/configpackageutility.cpp | 14 +++++----- lib/remote/configpackageutility.hpp | 4 +-- lib/remote/configstageshandler.cpp | 2 +- lib/remote/consolehandler.cpp | 6 ++-- lib/remote/endpoint.cpp | 8 +++--- lib/remote/endpoint.hpp | 2 +- lib/remote/eventqueue.cpp | 19 +++++++------ lib/remote/eventqueue.hpp | 7 ++--- 87 files changed, 312 insertions(+), 311 deletions(-) diff --git a/lib/base/configtype.cpp b/lib/base/configtype.cpp index 50a53d547..81f2c93d4 100644 --- a/lib/base/configtype.cpp +++ b/lib/base/configtype.cpp @@ -11,7 +11,7 @@ ConfigType::~ConfigType() ConfigObject::Ptr ConfigType::GetObject(const String& name) const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto nt = m_ObjectMap.find(name); @@ -26,7 +26,7 @@ void ConfigType::RegisterObject(const ConfigObject::Ptr& object) String name = object->GetName(); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto it = m_ObjectMap.find(name); @@ -51,7 +51,7 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object) String name = object->GetName(); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_ObjectMap.erase(name); m_ObjectVector.erase(std::remove(m_ObjectVector.begin(), m_ObjectVector.end(), object), m_ObjectVector.end()); @@ -60,7 +60,7 @@ void ConfigType::UnregisterObject(const ConfigObject::Ptr& object) std::vector ConfigType::GetObjects() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_ObjectVector; } @@ -71,6 +71,6 @@ std::vector ConfigType::GetObjectsHelper(Type *type) int ConfigType::GetObjectCount() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_ObjectVector.size(); } diff --git a/lib/base/configtype.hpp b/lib/base/configtype.hpp index 2244cc5fa..5008cd7a8 100644 --- a/lib/base/configtype.hpp +++ b/lib/base/configtype.hpp @@ -7,7 +7,7 @@ #include "base/object.hpp" #include "base/type.hpp" #include "base/dictionary.hpp" -#include +#include namespace icinga { @@ -51,7 +51,7 @@ private: typedef std::map > ObjectMap; typedef std::vector > ObjectVector; - mutable boost::mutex m_Mutex; + mutable std::mutex m_Mutex; ObjectMap m_ObjectMap; ObjectVector m_ObjectVector; diff --git a/lib/base/configwriter.cpp b/lib/base/configwriter.cpp index cef3f7eb8..c9dd58270 100644 --- a/lib/base/configwriter.cpp +++ b/lib/base/configwriter.cpp @@ -130,10 +130,10 @@ void ConfigWriter::EmitIndent(std::ostream& fp, int indentLevel) void ConfigWriter::EmitIdentifier(std::ostream& fp, const String& identifier, bool inAssignment) { static std::set keywords; - static boost::mutex mutex; + static std::mutex mutex; { - boost::mutex::scoped_lock lock(mutex); + std::unique_lock lock(mutex); if (keywords.empty()) { const std::vector& vkeywords = GetKeywords(); std::copy(vkeywords.begin(), vkeywords.end(), std::inserter(keywords, keywords.begin())); @@ -203,8 +203,8 @@ String ConfigWriter::EscapeIcingaString(const String& str) const std::vector& ConfigWriter::GetKeywords() { static std::vector keywords; - static boost::mutex mutex; - boost::mutex::scoped_lock lock(mutex); + static std::mutex mutex; + std::unique_lock lock(mutex); if (keywords.empty()) { keywords.emplace_back("object"); diff --git a/lib/base/dependencygraph.cpp b/lib/base/dependencygraph.cpp index 63763af95..025eb3ea3 100644 --- a/lib/base/dependencygraph.cpp +++ b/lib/base/dependencygraph.cpp @@ -4,18 +4,18 @@ using namespace icinga; -boost::mutex DependencyGraph::m_Mutex; +std::mutex DependencyGraph::m_Mutex; std::map > DependencyGraph::m_Dependencies; void DependencyGraph::AddDependency(Object *parent, Object *child) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Dependencies[child][parent]++; } void DependencyGraph::RemoveDependency(Object *parent, Object *child) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto& refs = m_Dependencies[child]; auto it = refs.find(parent); @@ -36,7 +36,7 @@ std::vector DependencyGraph::GetParents(const Object::Ptr& child) { std::vector objects; - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto it = m_Dependencies.find(child.get()); if (it != m_Dependencies.end()) { diff --git a/lib/base/dependencygraph.hpp b/lib/base/dependencygraph.hpp index 426607488..51aa90eca 100644 --- a/lib/base/dependencygraph.hpp +++ b/lib/base/dependencygraph.hpp @@ -5,8 +5,8 @@ #include "base/i2-base.hpp" #include "base/object.hpp" -#include #include +#include namespace icinga { @@ -25,7 +25,7 @@ public: private: DependencyGraph(); - static boost::mutex m_Mutex; + static std::mutex m_Mutex; static std::map > m_Dependencies; }; diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 4473bef8a..53698bf3c 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -27,7 +27,7 @@ template Log& Log::operator<<(const double&); REGISTER_TYPE(Logger); std::set Logger::m_Loggers; -boost::mutex Logger::m_Mutex; +std::mutex Logger::m_Mutex; bool Logger::m_ConsoleLogEnabled = true; bool Logger::m_TimestampEnabled = true; LogSeverity Logger::m_ConsoleLogSeverity = LogInformation; @@ -47,14 +47,14 @@ void Logger::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Loggers.insert(this); } void Logger::Stop(bool runtimeRemoved) { { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Loggers.erase(this); } @@ -63,7 +63,7 @@ void Logger::Stop(bool runtimeRemoved) std::set Logger::GetLoggers() { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_Loggers; } diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp index 4200fcc6c..59220b2fb 100644 --- a/lib/base/logger.hpp +++ b/lib/base/logger.hpp @@ -81,7 +81,7 @@ protected: void Stop(bool runtimeRemoved) override; private: - static boost::mutex m_Mutex; + static std::mutex m_Mutex; static std::set m_Loggers; static bool m_ConsoleLogEnabled; static bool m_TimestampEnabled; diff --git a/lib/base/object.cpp b/lib/base/object.cpp index 72f99adaf..e61cf8309 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -17,7 +17,7 @@ using namespace icinga; DEFINE_TYPE_INSTANCE(Object); #ifdef I2_LEAK_DEBUG -static boost::mutex l_ObjectCountLock; +static std::mutex l_ObjectCountLock; static std::map l_ObjectCounts; static Timer::Ptr l_ObjectCountTimer; #endif /* I2_LEAK_DEBUG */ @@ -203,21 +203,21 @@ Value icinga::GetPrototypeField(const Value& context, const String& field, bool #ifdef I2_LEAK_DEBUG void icinga::TypeAddObject(Object *object) { - boost::mutex::scoped_lock lock(l_ObjectCountLock); + std::unique_lock lock(l_ObjectCountLock); String typeName = Utility::GetTypeName(typeid(*object)); l_ObjectCounts[typeName]++; } void icinga::TypeRemoveObject(Object *object) { - boost::mutex::scoped_lock lock(l_ObjectCountLock); + std::unique_lock lock(l_ObjectCountLock); String typeName = Utility::GetTypeName(typeid(*object)); l_ObjectCounts[typeName]--; } static void TypeInfoTimerHandler() { - boost::mutex::scoped_lock lock(l_ObjectCountLock); + std::unique_lock lock(l_ObjectCountLock); typedef std::map::value_type kv_pair; for (kv_pair& kv : l_ObjectCounts) { diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 16106d21d..02750dfe8 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -33,7 +33,7 @@ using namespace icinga; #define IOTHREADS 4 -static boost::mutex l_ProcessMutex[IOTHREADS]; +static std::mutex l_ProcessMutex[IOTHREADS]; static std::map l_Processes[IOTHREADS]; #ifdef _WIN32 static HANDLE l_Events[IOTHREADS]; @@ -41,7 +41,7 @@ static HANDLE l_Events[IOTHREADS]; static int l_EventFDs[IOTHREADS][2]; static std::map l_FDs[IOTHREADS]; -static boost::mutex l_ProcessControlMutex; +static std::mutex l_ProcessControlMutex; static int l_ProcessControlFD = -1; static pid_t l_ProcessControlPID; #endif /* _WIN32 */ @@ -372,7 +372,7 @@ static pid_t ProcessSpawn(const std::vector& arguments, const Dictionary String jrequest = JsonEncode(request); size_t length = jrequest.GetLength(); - boost::mutex::scoped_lock lock(l_ProcessControlMutex); + std::unique_lock lock(l_ProcessControlMutex); struct msghdr msg; memset(&msg, 0, sizeof(msg)); @@ -431,7 +431,7 @@ static int ProcessKill(pid_t pid, int signum) String jrequest = JsonEncode(request); size_t length = jrequest.GetLength(); - boost::mutex::scoped_lock lock(l_ProcessControlMutex); + std::unique_lock lock(l_ProcessControlMutex); do { while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) { @@ -462,7 +462,7 @@ static int ProcessWaitPID(pid_t pid, int *status) String jrequest = JsonEncode(request); size_t length = jrequest.GetLength(); - boost::mutex::scoped_lock lock(l_ProcessControlMutex); + std::unique_lock lock(l_ProcessControlMutex); do { while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) { @@ -606,7 +606,7 @@ void Process::IOThreadProc(int tid) now = Utility::GetTime(); { - boost::mutex::scoped_lock lock(l_ProcessMutex[tid]); + std::unique_lock lock(l_ProcessMutex[tid]); count = 1 + l_Processes[tid].size(); #ifdef _WIN32 @@ -675,7 +675,7 @@ void Process::IOThreadProc(int tid) now = Utility::GetTime(); { - boost::mutex::scoped_lock lock(l_ProcessMutex[tid]); + std::unique_lock lock(l_ProcessMutex[tid]); #ifdef _WIN32 if (rc == WAIT_OBJECT_0) @@ -990,7 +990,7 @@ void Process::Run(const std::function& callback) int tid = GetTID(); { - boost::mutex::scoped_lock lock(l_ProcessMutex[tid]); + std::unique_lock lock(l_ProcessMutex[tid]); l_Processes[tid][m_Process] = this; #ifndef _WIN32 l_FDs[tid][m_FD] = m_Process; diff --git a/lib/base/registry.hpp b/lib/base/registry.hpp index b8b0aced2..c13f7e1b0 100644 --- a/lib/base/registry.hpp +++ b/lib/base/registry.hpp @@ -5,9 +5,9 @@ #include "base/i2-base.hpp" #include "base/string.hpp" -#include #include #include +#include namespace icinga { @@ -25,7 +25,7 @@ public: void RegisterIfNew(const String& name, const T& item) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); if (m_Items.find(name) != m_Items.end()) return; @@ -35,7 +35,7 @@ public: void Register(const String& name, const T& item) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); RegisterInternal(name, item, lock); } @@ -45,7 +45,7 @@ public: size_t erased; { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); erased = m_Items.erase(name); } @@ -58,7 +58,7 @@ public: typename Registry::ItemMap items; { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); items = m_Items; } @@ -67,14 +67,14 @@ public: } { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Items.clear(); } } T GetItem(const String& name) const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto it = m_Items.find(name); @@ -86,7 +86,7 @@ public: ItemMap GetItems() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_Items; /* Makes a copy of the map. */ } @@ -95,10 +95,10 @@ public: boost::signals2::signal OnUnregistered; private: - mutable boost::mutex m_Mutex; + mutable std::mutex m_Mutex; typename Registry::ItemMap m_Items; - void RegisterInternal(const String& name, const T& item, boost::mutex::scoped_lock& lock) + void RegisterInternal(const String& name, const T& item, std::unique_lock& lock) { bool old_item = false; diff --git a/lib/base/ringbuffer.cpp b/lib/base/ringbuffer.cpp index 75ffff3eb..52e2ae507 100644 --- a/lib/base/ringbuffer.cpp +++ b/lib/base/ringbuffer.cpp @@ -13,13 +13,13 @@ RingBuffer::RingBuffer(RingBuffer::SizeType slots) RingBuffer::SizeType RingBuffer::GetLength() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_Slots.size(); } void RingBuffer::InsertValue(RingBuffer::SizeType tv, int num) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); InsertValueUnlocked(tv, num); } @@ -55,7 +55,7 @@ void RingBuffer::InsertValueUnlocked(RingBuffer::SizeType tv, int num) int RingBuffer::UpdateAndGetValues(RingBuffer::SizeType tv, RingBuffer::SizeType span) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return UpdateAndGetValuesUnlocked(tv, span); } @@ -84,7 +84,7 @@ int RingBuffer::UpdateAndGetValuesUnlocked(RingBuffer::SizeType tv, RingBuffer:: double RingBuffer::CalculateRate(RingBuffer::SizeType tv, RingBuffer::SizeType span) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); int sum = UpdateAndGetValuesUnlocked(tv, span); return sum / static_cast(std::min(span, m_InsertedValues)); diff --git a/lib/base/ringbuffer.hpp b/lib/base/ringbuffer.hpp index ed5802829..9fbef53a7 100644 --- a/lib/base/ringbuffer.hpp +++ b/lib/base/ringbuffer.hpp @@ -5,8 +5,8 @@ #include "base/i2-base.hpp" #include "base/object.hpp" -#include #include +#include namespace icinga { @@ -31,7 +31,7 @@ public: double CalculateRate(SizeType tv, SizeType span); private: - mutable boost::mutex m_Mutex; + mutable std::mutex m_Mutex; std::vector m_Slots; SizeType m_TimeValue; SizeType m_InsertedValues; diff --git a/lib/base/singleton.hpp b/lib/base/singleton.hpp index bc4fa9cc2..77511c09a 100644 --- a/lib/base/singleton.hpp +++ b/lib/base/singleton.hpp @@ -4,7 +4,6 @@ #define SINGLETON_H #include "base/i2-base.hpp" -#include namespace icinga { diff --git a/lib/base/socket.cpp b/lib/base/socket.cpp index cc3183b96..4c967dee4 100644 --- a/lib/base/socket.cpp +++ b/lib/base/socket.cpp @@ -145,7 +145,7 @@ std::pair Socket::GetDetailsFromSockaddr(sockaddr *address, sock */ std::pair Socket::GetClientAddressDetails() { - boost::mutex::scoped_lock lock(m_SocketMutex); + std::unique_lock lock(m_SocketMutex); sockaddr_storage sin; socklen_t len = sizeof(sin); @@ -195,7 +195,7 @@ String Socket::GetClientAddress() */ std::pair Socket::GetPeerAddressDetails() { - boost::mutex::scoped_lock lock(m_SocketMutex); + std::unique_lock lock(m_SocketMutex); sockaddr_storage sin; socklen_t len = sizeof(sin); diff --git a/lib/base/socket.hpp b/lib/base/socket.hpp index a642fc496..f7acf7f52 100644 --- a/lib/base/socket.hpp +++ b/lib/base/socket.hpp @@ -5,7 +5,7 @@ #include "base/i2-base.hpp" #include "base/object.hpp" -#include +#include namespace icinga { @@ -50,7 +50,7 @@ protected: int GetError() const; - mutable boost::mutex m_SocketMutex; + mutable std::mutex m_SocketMutex; private: SOCKET m_FD{INVALID_SOCKET}; /**< The socket descriptor. */ diff --git a/lib/base/stream.cpp b/lib/base/stream.cpp index 77d39d3aa..d1e9c73d8 100644 --- a/lib/base/stream.cpp +++ b/lib/base/stream.cpp @@ -2,6 +2,7 @@ #include "base/stream.hpp" #include +#include using namespace icinga; @@ -38,7 +39,7 @@ void Stream::SignalDataAvailable() OnDataAvailable(this); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_CV.notify_all(); } } @@ -48,7 +49,7 @@ bool Stream::WaitForData() if (!SupportsWaiting()) BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support waiting.")); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); while (!IsDataAvailable() && !IsEof()) m_CV.wait(lock); @@ -58,20 +59,17 @@ bool Stream::WaitForData() bool Stream::WaitForData(int timeout) { + namespace ch = std::chrono; + if (!SupportsWaiting()) BOOST_THROW_EXCEPTION(std::runtime_error("Stream does not support waiting.")); if (timeout < 0) BOOST_THROW_EXCEPTION(std::runtime_error("Timeout can't be negative")); - boost::system_time const point_of_timeout = boost::get_system_time() + boost::posix_time::seconds(timeout); + std::unique_lock lock(m_Mutex); - boost::mutex::scoped_lock lock(m_Mutex); - - while (!IsDataAvailable() && !IsEof() && point_of_timeout > boost::get_system_time()) - m_CV.timed_wait(lock, point_of_timeout); - - return IsDataAvailable() || IsEof(); + return m_CV.wait_for(lock, ch::duration(timeout), [this]() { return IsDataAvailable() || IsEof(); }); } static void StreamDummyCallback() diff --git a/lib/base/stream.hpp b/lib/base/stream.hpp index 393a0aee4..6bc8fed72 100644 --- a/lib/base/stream.hpp +++ b/lib/base/stream.hpp @@ -6,8 +6,8 @@ #include "base/i2-base.hpp" #include "base/object.hpp" #include -#include -#include +#include +#include namespace icinga { @@ -124,8 +124,8 @@ protected: private: boost::signals2::signal OnDataAvailable; - boost::mutex m_Mutex; - boost::condition_variable m_CV; + std::mutex m_Mutex; + std::condition_variable m_CV; }; } diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index cd5e79981..fb8d9feff 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -11,7 +11,7 @@ using namespace icinga; REGISTER_TYPE(StreamLogger); -boost::mutex StreamLogger::m_Mutex; +std::mutex StreamLogger::m_Mutex; void StreamLogger::Stop(bool runtimeRemoved) { @@ -75,7 +75,7 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, const LogEntry& entry) { String timestamp = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", entry.Timestamp); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); if (Logger::IsTimestampEnabled()) stream << "[" << timestamp << "] "; diff --git a/lib/base/streamlogger.hpp b/lib/base/streamlogger.hpp index 81482aa98..8cbe313ce 100644 --- a/lib/base/streamlogger.hpp +++ b/lib/base/streamlogger.hpp @@ -33,7 +33,7 @@ protected: void Flush() final; private: - static boost::mutex m_Mutex; + static std::mutex m_Mutex; std::ostream *m_Stream{nullptr}; bool m_OwnsStream{false}; diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 6abac8566..973888e9f 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -5,11 +5,12 @@ #include "base/debug.hpp" #include "base/logger.hpp" #include "base/utility.hpp" -#include -#include #include #include #include +#include +#include +#include #include using namespace icinga; @@ -51,8 +52,8 @@ typedef boost::multi_index_container< > > TimerSet; -static boost::mutex l_TimerMutex; -static boost::condition_variable l_TimerCV; +static std::mutex l_TimerMutex; +static std::condition_variable l_TimerCV; static std::thread l_TimerThread; static bool l_StopTimerThread; static TimerSet l_Timers; @@ -70,7 +71,7 @@ Timer::~Timer() void Timer::Initialize() { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); if (l_AliveTimers > 0) { InitializeThread(); @@ -79,7 +80,7 @@ void Timer::Initialize() void Timer::Uninitialize() { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); if (l_AliveTimers > 0) { UninitializeThread(); @@ -130,7 +131,7 @@ void Timer::Call() */ void Timer::SetInterval(double interval) { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); m_Interval = interval; } @@ -141,7 +142,7 @@ void Timer::SetInterval(double interval) */ double Timer::GetInterval() const { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); return m_Interval; } @@ -151,7 +152,7 @@ double Timer::GetInterval() const void Timer::Start() { { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); m_Started = true; if (++l_AliveTimers == 1) { @@ -170,7 +171,7 @@ void Timer::Stop(bool wait) if (l_StopTimerThread) return; - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); if (m_Started && --l_AliveTimers == 0) { UninitializeThread(); @@ -200,7 +201,7 @@ void Timer::Reschedule(double next) */ void Timer::InternalReschedule(bool completed, double next) { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); if (completed) m_Running = false; @@ -232,7 +233,7 @@ void Timer::InternalReschedule(bool completed, double next) */ double Timer::GetNext() const { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); return m_Next; } @@ -244,7 +245,7 @@ double Timer::GetNext() const */ void Timer::AdjustTimers(double adjustment) { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); double now = Utility::GetTime(); @@ -275,12 +276,14 @@ void Timer::AdjustTimers(double adjustment) */ void Timer::TimerThreadProc() { + namespace ch = std::chrono; + Log(LogDebug, "Timer", "TimerThreadProc started."); Utility::SetThreadName("Timer Thread"); for (;;) { - boost::mutex::scoped_lock lock(l_TimerMutex); + std::unique_lock lock(l_TimerMutex); typedef boost::multi_index::nth_index::type NextTimerView; NextTimerView& idx = boost::get<1>(l_Timers); @@ -295,11 +298,11 @@ void Timer::TimerThreadProc() auto it = idx.begin(); Timer *timer = *it; - double wait = timer->m_Next - Utility::GetTime(); + ch::time_point> next (ch::duration(timer->m_Next)); - if (wait > 0.01) { + if (next - ch::system_clock::now() > ch::duration(0.01)) { /* Wait for the next timer. */ - l_TimerCV.timed_wait(lock, boost::posix_time::milliseconds(long(wait * 1000))); + l_TimerCV.wait_until(lock, next); continue; } diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index c9cecb07b..ac29fbc26 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -17,8 +17,8 @@ namespace icinga { static bool l_SSLInitialized = false; -static boost::mutex *l_Mutexes; -static boost::mutex l_RandomMutex; +static std::mutex *l_Mutexes; +static std::mutex l_RandomMutex; String GetOpenSSLVersion() { @@ -62,7 +62,7 @@ void InitializeOpenSSL() SSL_COMP_get_compression_methods(); #ifdef CRYPTO_LOCK - l_Mutexes = new boost::mutex[CRYPTO_num_locks()]; + l_Mutexes = new std::mutex[CRYPTO_num_locks()]; CRYPTO_set_locking_callback(&OpenSSLLockingCallback); CRYPTO_set_id_callback(&OpenSSLIDCallback); #endif /* CRYPTO_LOCK */ @@ -816,7 +816,7 @@ String RandomString(int length) /* Ensure that password generation is atomic. RAND_bytes is not thread-safe * in OpenSSL < 1.1.0. */ - boost::mutex::scoped_lock lock(l_RandomMutex); + std::unique_lock lock(l_RandomMutex); if (!RAND_bytes(bytes, length)) { delete [] bytes; diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp index 4593b34ba..ff2064f31 100644 --- a/lib/base/workqueue.cpp +++ b/lib/base/workqueue.cpp @@ -44,16 +44,16 @@ String WorkQueue::GetName() const return m_Name; } -boost::mutex::scoped_lock WorkQueue::AcquireLock() +std::unique_lock WorkQueue::AcquireLock() { - return boost::mutex::scoped_lock(m_Mutex); + return std::unique_lock(m_Mutex); } /** * Enqueues a task. Tasks are guaranteed to be executed in the order * they were enqueued in except if there is more than one worker thread. */ -void WorkQueue::EnqueueUnlocked(boost::mutex::scoped_lock& lock, std::function&& function, WorkQueuePriority priority) +void WorkQueue::EnqueueUnlocked(std::unique_lock& lock, std::function&& function, WorkQueuePriority priority) { if (!m_Spawned) { Log(LogNotice, "WorkQueue") @@ -107,7 +107,7 @@ void WorkQueue::Enqueue(std::function&& function, WorkQueuePriority pri */ void WorkQueue::Join(bool stop) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); while (m_Processing || !m_Tasks.empty()) m_CVStarved.wait(lock); @@ -153,7 +153,7 @@ void WorkQueue::SetExceptionCallback(const ExceptionCallback& callback) */ bool WorkQueue::HasExceptions() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return !m_Exceptions.empty(); } @@ -164,7 +164,7 @@ bool WorkQueue::HasExceptions() const */ std::vector WorkQueue::GetExceptions() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_Exceptions; } @@ -184,14 +184,14 @@ void WorkQueue::ReportExceptions(const String& facility, bool verbose) const size_t WorkQueue::GetLength() const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_Tasks.size(); } void WorkQueue::StatusTimerHandler() { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); ASSERT(!m_Name.IsEmpty()); @@ -238,7 +238,7 @@ void WorkQueue::RunTaskFunction(const TaskFunction& func) boost::exception_ptr eptr = boost::current_exception(); { - boost::mutex::scoped_lock mutex(m_Mutex); + std::unique_lock mutex(m_Mutex); if (!m_ExceptionCallback) m_Exceptions.push_back(eptr); @@ -257,7 +257,7 @@ void WorkQueue::WorkerThreadProc() l_ThreadWorkQueue.reset(new WorkQueue *(this)); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); for (;;) { while (m_Tasks.empty() && !m_Stopped) diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index 1c3df57b2..bb2d9af23 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -8,9 +8,9 @@ #include "base/ringbuffer.hpp" #include "base/logger.hpp" #include -#include -#include #include +#include +#include #include #include #include @@ -59,8 +59,8 @@ public: void SetName(const String& name); String GetName() const; - boost::mutex::scoped_lock AcquireLock(); - void EnqueueUnlocked(boost::mutex::scoped_lock& lock, TaskFunction&& function, WorkQueuePriority priority = PriorityNormal); + std::unique_lock AcquireLock(); + void EnqueueUnlocked(std::unique_lock& lock, TaskFunction&& function, WorkQueuePriority priority = PriorityNormal); void Enqueue(TaskFunction&& function, WorkQueuePriority priority = PriorityNormal, bool allowInterleaved = false); void Join(bool stop = false); @@ -116,10 +116,10 @@ private: int m_ThreadCount; bool m_Spawned{false}; - mutable boost::mutex m_Mutex; - boost::condition_variable m_CVEmpty; - boost::condition_variable m_CVFull; - boost::condition_variable m_CVStarved; + mutable std::mutex m_Mutex; + std::condition_variable m_CVEmpty; + std::condition_variable m_CVFull; + std::condition_variable m_CVStarved; boost::thread_group m_Threads; size_t m_MaxItems; bool m_Stopped{false}; diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index 0b5980acd..d3a04a48b 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -14,6 +14,7 @@ #include "base/exception.hpp" #include "base/convert.hpp" #include "base/statsfunction.hpp" +#include using namespace icinga; @@ -69,7 +70,7 @@ void CheckerComponent::Start(bool runtimeCreated) void CheckerComponent::Stop(bool runtimeRemoved) { { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Stopped = true; m_CV.notify_all(); } @@ -88,7 +89,7 @@ void CheckerComponent::CheckThreadProc() Utility::SetThreadName("Check Scheduler"); IcingaApplication::Ptr icingaApp = IcingaApplication::GetInstance(); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); for (;;) { typedef boost::multi_index::nth_index::type CheckTimeView; @@ -116,7 +117,7 @@ void CheckerComponent::CheckThreadProc() if (wait > 0) { /* Wait for the next check. */ - m_CV.timed_wait(lock, boost::posix_time::milliseconds(long(wait * 1000))); + m_CV.wait_for(lock, std::chrono::duration(wait)); continue; } @@ -229,7 +230,7 @@ void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable) Checkable::DecreasePendingChecks(); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); /* remove the object from the list of pending objects; if it's not in the * list this was a manual (i.e. forced) check and we must not re-add the @@ -255,7 +256,7 @@ void CheckerComponent::ResultTimerHandler() std::ostringstream msgbuf; { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); msgbuf << "Pending checkables: " << m_PendingCheckables.size() << "; Idle checkables: " << m_IdleCheckables.size() << "; Checks/s: " << (CIB::GetActiveHostChecksStatistics(60) + CIB::GetActiveServiceChecksStatistics(60)) / 60.0; @@ -275,7 +276,7 @@ void CheckerComponent::ObjectHandler(const ConfigObject::Ptr& object) bool same_zone = (!zone || Zone::GetLocalZone() == zone); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); if (object->IsActive() && !object->IsPaused() && same_zone) { if (m_PendingCheckables.find(checkable) != m_PendingCheckables.end()) @@ -301,7 +302,7 @@ CheckableScheduleInfo CheckerComponent::GetCheckableScheduleInfo(const Checkable void CheckerComponent::NextCheckChangedHandler(const Checkable::Ptr& checkable) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); /* remove and re-insert the object from the set in order to force an index update */ typedef boost::multi_index::nth_index::type CheckableView; @@ -322,14 +323,14 @@ void CheckerComponent::NextCheckChangedHandler(const Checkable::Ptr& checkable) unsigned long CheckerComponent::GetIdleCheckables() { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_IdleCheckables.size(); } unsigned long CheckerComponent::GetPendingCheckables() { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_PendingCheckables.size(); } diff --git a/lib/checker/checkercomponent.hpp b/lib/checker/checkercomponent.hpp index b3589e5fb..5ace7571c 100644 --- a/lib/checker/checkercomponent.hpp +++ b/lib/checker/checkercomponent.hpp @@ -8,11 +8,11 @@ #include "base/configobject.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include -#include #include #include #include +#include +#include #include namespace icinga @@ -69,8 +69,8 @@ public: unsigned long GetPendingCheckables(); private: - boost::mutex m_Mutex; - boost::condition_variable m_CV; + std::mutex m_Mutex; + std::condition_variable m_CV; bool m_Stopped{false}; std::thread m_Thread; diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp index 878beac77..cfdce0946 100644 --- a/lib/cli/clicommand.cpp +++ b/lib/cli/clicommand.cpp @@ -95,9 +95,9 @@ bool CLICommand::IsDeprecated() const return false; } -boost::mutex& CLICommand::GetRegistryMutex() +std::mutex& CLICommand::GetRegistryMutex() { - static boost::mutex mtx; + static std::mutex mtx; return mtx; } @@ -109,7 +109,7 @@ std::map, CLICommand::Ptr>& CLICommand::GetRegistry() CLICommand::Ptr CLICommand::GetByName(const std::vector& name) { - boost::mutex::scoped_lock lock(GetRegistryMutex()); + std::unique_lock lock(GetRegistryMutex()); auto it = GetRegistry().find(name); @@ -121,13 +121,13 @@ CLICommand::Ptr CLICommand::GetByName(const std::vector& name) void CLICommand::Register(const std::vector& name, const CLICommand::Ptr& function) { - boost::mutex::scoped_lock lock(GetRegistryMutex()); + std::unique_lock lock(GetRegistryMutex()); GetRegistry()[name] = function; } void CLICommand::Unregister(const std::vector& name) { - boost::mutex::scoped_lock lock(GetRegistryMutex()); + std::unique_lock lock(GetRegistryMutex()); GetRegistry().erase(name); } @@ -155,7 +155,7 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi po::positional_options_description& positionalDesc, po::variables_map& vm, String& cmdname, CLICommand::Ptr& command, bool autocomplete) { - boost::mutex::scoped_lock lock(GetRegistryMutex()); + std::unique_lock lock(GetRegistryMutex()); typedef std::map, CLICommand::Ptr>::value_type CLIKeyValue; @@ -224,7 +224,7 @@ void CLICommand::ShowCommands(int argc, char **argv, po::options_description *vi ArgumentCompletionCallback globalArgCompletionCallback, bool autocomplete, int autoindex) { - boost::mutex::scoped_lock lock(GetRegistryMutex()); + std::unique_lock lock(GetRegistryMutex()); typedef std::map, CLICommand::Ptr>::value_type CLIKeyValue; diff --git a/lib/cli/clicommand.hpp b/lib/cli/clicommand.hpp index e3bbae171..ce58b54b8 100644 --- a/lib/cli/clicommand.hpp +++ b/lib/cli/clicommand.hpp @@ -64,7 +64,7 @@ public: bool autocomplete = false, int autoindex = -1); private: - static boost::mutex& GetRegistryMutex(); + static std::mutex& GetRegistryMutex(); static std::map, CLICommand::Ptr>& GetRegistry(); }; diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index 41b6590e4..b54966e7b 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -117,8 +117,8 @@ extern "C" void dbg_eval_with_object(Object *object, const char *text) void ConsoleCommand::BreakpointHandler(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di) { - static boost::mutex mutex; - boost::mutex::scoped_lock lock(mutex); + static std::mutex mutex; + std::unique_lock lock(mutex); if (!Application::GetScriptDebuggerEnabled()) return; diff --git a/lib/cli/consolecommand.hpp b/lib/cli/consolecommand.hpp index 973ca7f19..631ec2164 100644 --- a/lib/cli/consolecommand.hpp +++ b/lib/cli/consolecommand.hpp @@ -8,6 +8,7 @@ #include "base/scriptframe.hpp" #include "base/tlsstream.hpp" #include "remote/url.hpp" +#include namespace icinga @@ -37,8 +38,8 @@ public: bool syntaxOnly = false); private: - mutable boost::mutex m_Mutex; - mutable boost::condition_variable m_CV; + mutable std::mutex m_Mutex; + mutable std::condition_variable m_CV; static Shared::Ptr Connect(); diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index 59285eac4..d97d82586 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -12,7 +12,7 @@ using namespace icinga; std::vector ConfigCompiler::m_IncludeSearchDirs; -boost::mutex ConfigCompiler::m_ZoneDirsMutex; +std::mutex ConfigCompiler::m_ZoneDirsMutex; std::map > ConfigCompiler::m_ZoneDirs; /** @@ -296,7 +296,7 @@ void ConfigCompiler::AddIncludeSearchDir(const String& dir) std::vector ConfigCompiler::GetZoneDirs(const String& zone) { - boost::mutex::scoped_lock lock(m_ZoneDirsMutex); + std::unique_lock lock(m_ZoneDirsMutex); auto it = m_ZoneDirs.find(zone); if (it == m_ZoneDirs.end()) return std::vector(); @@ -310,7 +310,7 @@ void ConfigCompiler::RegisterZoneDir(const String& tag, const String& ppath, con zf.Tag = tag; zf.Path = ppath; - boost::mutex::scoped_lock lock(m_ZoneDirsMutex); + std::unique_lock lock(m_ZoneDirsMutex); m_ZoneDirs[zoneName].push_back(zf); } diff --git a/lib/config/configcompiler.hpp b/lib/config/configcompiler.hpp index 961e3d238..fe00bedfc 100644 --- a/lib/config/configcompiler.hpp +++ b/lib/config/configcompiler.hpp @@ -126,7 +126,7 @@ private: void *m_Scanner; static std::vector m_IncludeSearchDirs; - static boost::mutex m_ZoneDirsMutex; + static std::mutex m_ZoneDirsMutex; static std::map > m_ZoneDirs; void InitializeScanner(); diff --git a/lib/config/configcompilercontext.cpp b/lib/config/configcompilercontext.cpp index 7be89fff6..666fe560e 100644 --- a/lib/config/configcompilercontext.cpp +++ b/lib/config/configcompilercontext.cpp @@ -41,7 +41,7 @@ void ConfigCompilerContext::WriteObject(const Dictionary::Ptr& object) String json = JsonEncode(object); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); NetString::WriteStringToStream(*m_ObjectsFP, json); } } diff --git a/lib/config/configcompilercontext.hpp b/lib/config/configcompilercontext.hpp index 58c55d539..f02e26869 100644 --- a/lib/config/configcompilercontext.hpp +++ b/lib/config/configcompilercontext.hpp @@ -5,8 +5,8 @@ #include "config/i2-config.hpp" #include "base/dictionary.hpp" -#include #include +#include namespace icinga { @@ -29,7 +29,7 @@ private: String m_ObjectsTempFile; std::fstream *m_ObjectsFP{nullptr}; - mutable boost::mutex m_Mutex; + mutable std::mutex m_Mutex; }; } diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index f3272a2f5..da91efc58 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -28,7 +28,7 @@ using namespace icinga; -boost::mutex ConfigItem::m_Mutex; +std::mutex ConfigItem::m_Mutex; ConfigItem::TypeMap ConfigItem::m_Items; ConfigItem::TypeMap ConfigItem::m_DefaultTemplates; ConfigItem::ItemList ConfigItem::m_UnnamedItems; @@ -195,7 +195,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) << "Ignoring config object '" << m_Name << "' of type '" << type->GetName() << "' due to errors: " << DiagnosticInformation(ex); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_IgnoredItems.push_back(m_DebugInfo.Path); } @@ -247,7 +247,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) << "Ignoring config object '" << m_Name << "' of type '" << type->GetName() << "' due to errors: " << DiagnosticInformation(ex); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_IgnoredItems.push_back(m_DebugInfo.Path); } @@ -266,7 +266,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) << "Ignoring config object '" << m_Name << "' of type '" << m_Type->GetName() << "' due to errors: " << DiagnosticInformation(ex); { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_IgnoredItems.push_back(m_DebugInfo.Path); } @@ -317,7 +317,7 @@ void ConfigItem::Register() { m_ActivationContext = ActivationContext::GetCurrentContext(); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); /* If this is a non-abstract object with a composite name * we register it in m_UnnamedItems instead of m_Items. */ @@ -353,7 +353,7 @@ void ConfigItem::Unregister() m_Object.reset(); } - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_UnnamedItems.erase(std::remove(m_UnnamedItems.begin(), m_UnnamedItems.end(), this), m_UnnamedItems.end()); m_Items[m_Type].erase(m_Name); m_DefaultTemplates[m_Type].erase(m_Name); @@ -368,7 +368,7 @@ void ConfigItem::Unregister() */ ConfigItem::Ptr ConfigItem::GetByTypeAndName(const Type::Ptr& type, const String& name) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto it = m_Items.find(type); @@ -389,7 +389,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue std::vector items; { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); for (const TypeMap::value_type& kv : m_Items) { for (const ItemMap::value_type& kv2 : kv.second) { @@ -534,7 +534,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue item->Unregister(); { - boost::mutex::scoped_lock lock(item->m_Mutex); + std::unique_lock lock(item->m_Mutex); item->m_IgnoredItems.push_back(item->m_DebugInfo.Path); } } @@ -627,8 +627,8 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u bool ConfigItem::ActivateItems(const std::vector& newItems, bool runtimeCreated, bool silent, bool withModAttrs, const Value& cookie) { - static boost::mutex mtx; - boost::mutex::scoped_lock lock(mtx); + static std::mutex mtx; + std::unique_lock lock(mtx); if (withModAttrs) { /* restore modified attributes */ @@ -730,7 +730,7 @@ std::vector ConfigItem::GetItems(const Type::Ptr& type) { std::vector items; - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto it = m_Items.find(type); @@ -750,7 +750,7 @@ std::vector ConfigItem::GetDefaultTemplates(const Type::Ptr& ty { std::vector items; - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto it = m_DefaultTemplates.find(type); @@ -768,7 +768,7 @@ std::vector ConfigItem::GetDefaultTemplates(const Type::Ptr& ty void ConfigItem::RemoveIgnoredItems(const String& allowedConfigPath) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); for (const String& path : m_IgnoredItems) { if (path.Find(allowedConfigPath) == String::NPos) diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index b1c9973cf..b3e4ca35d 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -80,7 +80,7 @@ private: ConfigObject::Ptr m_Object; - static boost::mutex m_Mutex; + static std::mutex m_Mutex; typedef std::map ItemMap; typedef std::map TypeMap; diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 4afe82583..a8337ff9e 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -522,13 +522,13 @@ void DbConnection::IncreaseQueryCount() { double now = Utility::GetTime(); - boost::mutex::scoped_lock lock(m_StatsMutex); + std::unique_lock lock(m_StatsMutex); m_QueryStats.InsertValue(now, 1); } int DbConnection::GetQueryCount(RingBuffer::SizeType span) { - boost::mutex::scoped_lock lock(m_StatsMutex); + std::unique_lock lock(m_StatsMutex); return m_QueryStats.UpdateAndGetValues(Utility::GetTime(), span); } diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index a7749d7fa..b0c04bd73 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -10,7 +10,7 @@ #include "base/timer.hpp" #include "base/ringbuffer.hpp" #include -#include +#include #define IDO_CURRENT_SCHEMA_VERSION "1.14.3" #define IDO_COMPAT_SCHEMA_VERSION "1.14.3" @@ -118,7 +118,7 @@ private: static void InsertRuntimeVariable(const String& key, const Value& value); - mutable boost::mutex m_StatsMutex; + mutable std::mutex m_StatsMutex; RingBuffer m_QueryStats{15 * 60}; bool m_ActiveChangedHandler{false}; diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index 180abe844..de5f54b86 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -347,7 +347,7 @@ void DbObject::OnStatusUpdate() DbObject::Ptr DbObject::GetOrCreateByObject(const ConfigObject::Ptr& object) { - boost::mutex::scoped_lock lock(GetStaticMutex()); + std::unique_lock lock(GetStaticMutex()); DbObject::Ptr dbobj = object->GetExtension("DbObject"); @@ -422,8 +422,8 @@ void DbObject::VersionChangedHandler(const ConfigObject::Ptr& object) } } -boost::mutex& DbObject::GetStaticMutex() +std::mutex& DbObject::GetStaticMutex() { - static boost::mutex mutex; + static std::mutex mutex; return mutex; } diff --git a/lib/db_ido/dbobject.hpp b/lib/db_ido/dbobject.hpp index 21c23504c..1b07f6006 100644 --- a/lib/db_ido/dbobject.hpp +++ b/lib/db_ido/dbobject.hpp @@ -96,7 +96,7 @@ private: static void VarsChangedHandler(const CustomVarObject::Ptr& object); static void VersionChangedHandler(const ConfigObject::Ptr& object); - static boost::mutex& GetStaticMutex(); + static std::mutex& GetStaticMutex(); friend class DbType; }; diff --git a/lib/db_ido/dbtype.cpp b/lib/db_ido/dbtype.cpp index 0870490cb..bc45dcb65 100644 --- a/lib/db_ido/dbtype.cpp +++ b/lib/db_ido/dbtype.cpp @@ -34,7 +34,7 @@ String DbType::GetIDColumn() const void DbType::RegisterType(const DbType::Ptr& type) { - boost::mutex::scoped_lock lock(GetStaticMutex()); + std::unique_lock lock(GetStaticMutex()); GetTypes()[type->GetName()] = type; } @@ -47,7 +47,7 @@ DbType::Ptr DbType::GetByName(const String& name) else typeName = name; - boost::mutex::scoped_lock lock(GetStaticMutex()); + std::unique_lock lock(GetStaticMutex()); auto it = GetTypes().find(typeName); if (it == GetTypes().end()) @@ -58,7 +58,7 @@ DbType::Ptr DbType::GetByName(const String& name) DbType::Ptr DbType::GetByID(long tid) { - boost::mutex::scoped_lock lock(GetStaticMutex()); + std::unique_lock lock(GetStaticMutex()); for (const TypeMap::value_type& kv : GetTypes()) { if (kv.second->GetTypeID() == tid) @@ -105,9 +105,9 @@ DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String& return dbobj; } -boost::mutex& DbType::GetStaticMutex() +std::mutex& DbType::GetStaticMutex() { - static boost::mutex mutex; + static std::mutex mutex; return mutex; } @@ -125,7 +125,7 @@ std::set DbType::GetAllTypes() std::set result; { - boost::mutex::scoped_lock lock(GetStaticMutex()); + std::unique_lock lock(GetStaticMutex()); for (const auto& kv : GetTypes()) { result.insert(kv.second); } diff --git a/lib/db_ido/dbtype.hpp b/lib/db_ido/dbtype.hpp index a667ecc6e..c8ebc4504 100644 --- a/lib/db_ido/dbtype.hpp +++ b/lib/db_ido/dbtype.hpp @@ -51,7 +51,7 @@ private: String m_IDColumn; ObjectFactory m_ObjectFactory; - static boost::mutex& GetStaticMutex(); + static std::mutex& GetStaticMutex(); static TypeMap& GetTypes(); ObjectMap m_Objects; diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index da1e8bd39..7461f7cd8 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -25,9 +25,9 @@ boost::signals2::signal Checkable::OnNextCheckUpda Atomic Checkable::CurrentConcurrentChecks (0); -boost::mutex Checkable::m_StatsMutex; +std::mutex Checkable::m_StatsMutex; int Checkable::m_PendingChecks = 0; -boost::condition_variable Checkable::m_PendingChecksCV; +std::condition_variable Checkable::m_PendingChecksCV; CheckCommand::Ptr Checkable::GetCheckCommand() const { @@ -659,26 +659,26 @@ void Checkable::UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type) void Checkable::IncreasePendingChecks() { - boost::mutex::scoped_lock lock(m_StatsMutex); + std::unique_lock lock(m_StatsMutex); m_PendingChecks++; } void Checkable::DecreasePendingChecks() { - boost::mutex::scoped_lock lock(m_StatsMutex); + std::unique_lock lock(m_StatsMutex); m_PendingChecks--; m_PendingChecksCV.notify_one(); } int Checkable::GetPendingChecks() { - boost::mutex::scoped_lock lock(m_StatsMutex); + std::unique_lock lock(m_StatsMutex); return m_PendingChecks; } void Checkable::AquirePendingCheckSlot(int maxPendingChecks) { - boost::mutex::scoped_lock lock(m_StatsMutex); + std::unique_lock lock(m_StatsMutex); while (m_PendingChecks >= maxPendingChecks) m_PendingChecksCV.wait(lock); diff --git a/lib/icinga/checkable-comment.cpp b/lib/icinga/checkable-comment.cpp index 88f5a5207..ea4f8b595 100644 --- a/lib/icinga/checkable-comment.cpp +++ b/lib/icinga/checkable-comment.cpp @@ -38,18 +38,18 @@ void Checkable::RemoveCommentsByType(int type, const String& removedBy) std::set Checkable::GetComments() const { - boost::mutex::scoped_lock lock(m_CommentMutex); + std::unique_lock lock(m_CommentMutex); return m_Comments; } void Checkable::RegisterComment(const Comment::Ptr& comment) { - boost::mutex::scoped_lock lock(m_CommentMutex); + std::unique_lock lock(m_CommentMutex); m_Comments.insert(comment); } void Checkable::UnregisterComment(const Comment::Ptr& comment) { - boost::mutex::scoped_lock lock(m_CommentMutex); + std::unique_lock lock(m_CommentMutex); m_Comments.erase(comment); } diff --git a/lib/icinga/checkable-dependency.cpp b/lib/icinga/checkable-dependency.cpp index 821c883a6..5ce92886c 100644 --- a/lib/icinga/checkable-dependency.cpp +++ b/lib/icinga/checkable-dependency.cpp @@ -8,37 +8,37 @@ using namespace icinga; void Checkable::AddDependency(const Dependency::Ptr& dep) { - boost::mutex::scoped_lock lock(m_DependencyMutex); + std::unique_lock lock(m_DependencyMutex); m_Dependencies.insert(dep); } void Checkable::RemoveDependency(const Dependency::Ptr& dep) { - boost::mutex::scoped_lock lock(m_DependencyMutex); + std::unique_lock lock(m_DependencyMutex); m_Dependencies.erase(dep); } std::vector Checkable::GetDependencies() const { - boost::mutex::scoped_lock lock(m_DependencyMutex); + std::unique_lock lock(m_DependencyMutex); return std::vector(m_Dependencies.begin(), m_Dependencies.end()); } void Checkable::AddReverseDependency(const Dependency::Ptr& dep) { - boost::mutex::scoped_lock lock(m_DependencyMutex); + std::unique_lock lock(m_DependencyMutex); m_ReverseDependencies.insert(dep); } void Checkable::RemoveReverseDependency(const Dependency::Ptr& dep) { - boost::mutex::scoped_lock lock(m_DependencyMutex); + std::unique_lock lock(m_DependencyMutex); m_ReverseDependencies.erase(dep); } std::vector Checkable::GetReverseDependencies() const { - boost::mutex::scoped_lock lock(m_DependencyMutex); + std::unique_lock lock(m_DependencyMutex); return std::vector(m_ReverseDependencies.begin(), m_ReverseDependencies.end()); } diff --git a/lib/icinga/checkable-downtime.cpp b/lib/icinga/checkable-downtime.cpp index dcc1539a8..f0c1c9c97 100644 --- a/lib/icinga/checkable-downtime.cpp +++ b/lib/icinga/checkable-downtime.cpp @@ -47,18 +47,18 @@ int Checkable::GetDowntimeDepth() const std::set Checkable::GetDowntimes() const { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + std::unique_lock lock(m_DowntimeMutex); return m_Downtimes; } void Checkable::RegisterDowntime(const Downtime::Ptr& downtime) { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + std::unique_lock lock(m_DowntimeMutex); m_Downtimes.insert(downtime); } void Checkable::UnregisterDowntime(const Downtime::Ptr& downtime) { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + std::unique_lock lock(m_DowntimeMutex); m_Downtimes.erase(downtime); } diff --git a/lib/icinga/checkable-notification.cpp b/lib/icinga/checkable-notification.cpp index 7d9fcb6b1..52e330a62 100644 --- a/lib/icinga/checkable-notification.cpp +++ b/lib/icinga/checkable-notification.cpp @@ -113,19 +113,19 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr& std::set Checkable::GetNotifications() const { - boost::mutex::scoped_lock lock(m_NotificationMutex); + std::unique_lock lock(m_NotificationMutex); return m_Notifications; } void Checkable::RegisterNotification(const Notification::Ptr& notification) { - boost::mutex::scoped_lock lock(m_NotificationMutex); + std::unique_lock lock(m_NotificationMutex); m_Notifications.insert(notification); } void Checkable::UnregisterNotification(const Notification::Ptr& notification) { - boost::mutex::scoped_lock lock(m_NotificationMutex); + std::unique_lock lock(m_NotificationMutex); m_Notifications.erase(notification); } diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 93aa7bb52..ae0859082 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -99,7 +99,7 @@ void Checkable::Start(bool runtimeCreated) void Checkable::AddGroup(const String& name) { - boost::mutex::scoped_lock lock(m_CheckableMutex); + std::unique_lock lock(m_CheckableMutex); Array::Ptr groups; auto *host = dynamic_cast(this); diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index c9799f07a..e51f6737d 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -14,6 +14,7 @@ #include "icinga/downtime.hpp" #include "remote/endpoint.hpp" #include "remote/messageorigin.hpp" +#include #include #include @@ -189,17 +190,17 @@ protected: void OnAllConfigLoaded() override; private: - mutable boost::mutex m_CheckableMutex; + mutable std::mutex m_CheckableMutex; bool m_CheckRunning{false}; long m_SchedulingOffset; - static boost::mutex m_StatsMutex; + static std::mutex m_StatsMutex; static int m_PendingChecks; - static boost::condition_variable m_PendingChecksCV; + static std::condition_variable m_PendingChecksCV; /* Downtimes */ std::set m_Downtimes; - mutable boost::mutex m_DowntimeMutex; + mutable std::mutex m_DowntimeMutex; static void NotifyFixedDowntimeStart(const Downtime::Ptr& downtime); static void NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime); @@ -212,14 +213,14 @@ private: /* Comments */ std::set m_Comments; - mutable boost::mutex m_CommentMutex; + mutable std::mutex m_CommentMutex; /* Notifications */ std::set m_Notifications; - mutable boost::mutex m_NotificationMutex; + mutable std::mutex m_NotificationMutex; /* Dependencies */ - mutable boost::mutex m_DependencyMutex; + mutable std::mutex m_DependencyMutex; std::set > m_Dependencies; std::set > m_ReverseDependencies; diff --git a/lib/icinga/cib.hpp b/lib/icinga/cib.hpp index 2abbb4600..00461e31f 100644 --- a/lib/icinga/cib.hpp +++ b/lib/icinga/cib.hpp @@ -79,7 +79,7 @@ public: private: CIB(); - static boost::mutex m_Mutex; + static std::mutex m_Mutex; static RingBuffer m_ActiveHostChecksStatistics; static RingBuffer m_PassiveHostChecksStatistics; static RingBuffer m_ActiveServiceChecksStatistics; diff --git a/lib/icinga/clusterevents-check.cpp b/lib/icinga/clusterevents-check.cpp index 30745dbd7..552fbd648 100644 --- a/lib/icinga/clusterevents-check.cpp +++ b/lib/icinga/clusterevents-check.cpp @@ -12,7 +12,7 @@ using namespace icinga; -boost::mutex ClusterEvents::m_Mutex; +std::mutex ClusterEvents::m_Mutex; std::deque> ClusterEvents::m_CheckRequestQueue; bool ClusterEvents::m_CheckSchedulerRunning; int ClusterEvents::m_ChecksExecutedDuringInterval; @@ -25,7 +25,7 @@ void ClusterEvents::RemoteCheckThreadProc() int maxConcurrentChecks = IcingaApplication::GetInstance()->GetMaxConcurrentChecks(); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); for(;;) { if (m_CheckRequestQueue.empty()) @@ -60,7 +60,7 @@ void ClusterEvents::EnqueueCheck(const MessageOrigin::Ptr& origin, const Diction m_LogTimer->Start(); }); - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); if (m_CheckRequestQueue.size() >= 25000) { m_ChecksDroppedDuringInterval++; diff --git a/lib/icinga/clusterevents.hpp b/lib/icinga/clusterevents.hpp index 1620b26b2..2a372d347 100644 --- a/lib/icinga/clusterevents.hpp +++ b/lib/icinga/clusterevents.hpp @@ -73,7 +73,7 @@ public: static void LogRemoteCheckQueueInformation(); private: - static boost::mutex m_Mutex; + static std::mutex m_Mutex; static std::deque> m_CheckRequestQueue; static bool m_CheckSchedulerRunning; static int m_ChecksExecutedDuringInterval; diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 0945724ea..ef7c8ba5c 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -12,7 +12,7 @@ using namespace icinga; static int l_NextCommentID = 1; -static boost::mutex l_CommentMutex; +static std::mutex l_CommentMutex; static std::map l_LegacyCommentsCache; static Timer::Ptr l_CommentsExpireTimer; @@ -87,7 +87,7 @@ void Comment::Start(bool runtimeCreated) }); { - boost::mutex::scoped_lock lock(l_CommentMutex); + std::unique_lock lock(l_CommentMutex); SetLegacyId(l_NextCommentID); l_LegacyCommentsCache[l_NextCommentID] = GetName(); @@ -124,7 +124,7 @@ bool Comment::IsExpired() const int Comment::GetNextCommentID() { - boost::mutex::scoped_lock lock(l_CommentMutex); + std::unique_lock lock(l_CommentMutex); return l_NextCommentID; } @@ -209,7 +209,7 @@ void Comment::RemoveComment(const String& id, const MessageOrigin::Ptr& origin) String Comment::GetCommentIDFromLegacyID(int id) { - boost::mutex::scoped_lock lock(l_CommentMutex); + std::unique_lock lock(l_CommentMutex); auto it = l_LegacyCommentsCache.find(id); diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index f7b86fd30..9e419ec24 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -13,7 +13,7 @@ using namespace icinga; static int l_NextDowntimeID = 1; -static boost::mutex l_DowntimeMutex; +static std::mutex l_DowntimeMutex; static std::map l_LegacyDowntimesCache; static Timer::Ptr l_DowntimesExpireTimer; static Timer::Ptr l_DowntimesStartTimer; @@ -103,7 +103,7 @@ void Downtime::Start(bool runtimeCreated) }); { - boost::mutex::scoped_lock lock(l_DowntimeMutex); + std::unique_lock lock(l_DowntimeMutex); SetLegacyId(l_NextDowntimeID); l_LegacyDowntimesCache[l_NextDowntimeID] = GetName(); @@ -201,7 +201,7 @@ bool Downtime::HasValidConfigOwner() const int Downtime::GetNextDowntimeID() { - boost::mutex::scoped_lock lock(l_DowntimeMutex); + std::unique_lock lock(l_DowntimeMutex); return l_NextDowntimeID; } @@ -405,7 +405,7 @@ void Downtime::TriggerDowntime() String Downtime::GetDowntimeIDFromLegacyID(int id) { - boost::mutex::scoped_lock lock(l_DowntimeMutex); + std::unique_lock lock(l_DowntimeMutex); auto it = l_LegacyDowntimesCache.find(id); diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 6f6f1facb..1c7e67bd5 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -68,7 +68,7 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const }); { - boost::mutex::scoped_lock lock(GetMutex()); + std::unique_lock lock(GetMutex()); auto it = GetCommands().find(command); @@ -107,7 +107,7 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs, size_t maxArgs) { - boost::mutex::scoped_lock lock(GetMutex()); + std::unique_lock lock(GetMutex()); ExternalCommandInfo eci; eci.Callback = callback; eci.MinArgs = minArgs; @@ -2267,9 +2267,9 @@ void ExternalCommandProcessor::DisableServicegroupSvcNotifications(double, const } } -boost::mutex& ExternalCommandProcessor::GetMutex() +std::mutex& ExternalCommandProcessor::GetMutex() { - static boost::mutex mtx; + static std::mutex mtx; return mtx; } diff --git a/lib/icinga/externalcommandprocessor.hpp b/lib/icinga/externalcommandprocessor.hpp index f7f0d75d6..a7c5a3068 100644 --- a/lib/icinga/externalcommandprocessor.hpp +++ b/lib/icinga/externalcommandprocessor.hpp @@ -159,7 +159,7 @@ private: static void RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX); static void RegisterCommands(); - static boost::mutex& GetMutex(); + static std::mutex& GetMutex(); static std::map& GetCommands(); }; diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 7bb1c434d..6cddc5feb 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -84,7 +84,7 @@ void Host::Stop(bool runtimeRemoved) std::vector Host::GetServices() const { - boost::mutex::scoped_lock lock(m_ServicesMutex); + std::unique_lock lock(m_ServicesMutex); std::vector services; services.reserve(m_Services.size()); @@ -98,14 +98,14 @@ std::vector Host::GetServices() const void Host::AddService(const Service::Ptr& service) { - boost::mutex::scoped_lock lock(m_ServicesMutex); + std::unique_lock lock(m_ServicesMutex); m_Services[service->GetShortName()] = service; } void Host::RemoveService(const Service::Ptr& service) { - boost::mutex::scoped_lock lock(m_ServicesMutex); + std::unique_lock lock(m_ServicesMutex); m_Services.erase(service->GetShortName()); } @@ -119,7 +119,7 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) { if (name.IsScalar()) { { - boost::mutex::scoped_lock lock(m_ServicesMutex); + std::unique_lock lock(m_ServicesMutex); auto it = m_Services.find(name); diff --git a/lib/icinga/host.hpp b/lib/icinga/host.hpp index 237d8aaa1..87f560af5 100644 --- a/lib/icinga/host.hpp +++ b/lib/icinga/host.hpp @@ -57,7 +57,7 @@ protected: void CreateChildObjects(const Type::Ptr& childType) override; private: - mutable boost::mutex m_ServicesMutex; + mutable std::mutex m_ServicesMutex; std::map > m_Services; static void RefreshServicesCache(); diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index 02dc6d7c9..a99d8ee54 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -58,7 +58,7 @@ void HostGroup::EvaluateObjectRules(const Host::Ptr& host) std::set HostGroup::GetMembers() const { - boost::mutex::scoped_lock lock(m_HostGroupMutex); + std::unique_lock lock(m_HostGroupMutex); return m_Members; } @@ -66,13 +66,13 @@ void HostGroup::AddMember(const Host::Ptr& host) { host->AddGroup(GetName()); - boost::mutex::scoped_lock lock(m_HostGroupMutex); + std::unique_lock lock(m_HostGroupMutex); m_Members.insert(host); } void HostGroup::RemoveMember(const Host::Ptr& host) { - boost::mutex::scoped_lock lock(m_HostGroupMutex); + std::unique_lock lock(m_HostGroupMutex); m_Members.erase(host); } diff --git a/lib/icinga/hostgroup.hpp b/lib/icinga/hostgroup.hpp index 283930a23..3ad5d269a 100644 --- a/lib/icinga/hostgroup.hpp +++ b/lib/icinga/hostgroup.hpp @@ -32,7 +32,7 @@ public: static void EvaluateObjectRules(const Host::Ptr& host); private: - mutable boost::mutex m_HostGroupMutex; + mutable std::mutex m_HostGroupMutex; std::set m_Members; static bool EvaluateObjectRule(const Host::Ptr& host, const intrusive_ptr& item); diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index 45d953f63..8784b50a9 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -61,7 +61,7 @@ void ServiceGroup::EvaluateObjectRules(const Service::Ptr& service) std::set ServiceGroup::GetMembers() const { - boost::mutex::scoped_lock lock(m_ServiceGroupMutex); + std::unique_lock lock(m_ServiceGroupMutex); return m_Members; } @@ -69,13 +69,13 @@ void ServiceGroup::AddMember(const Service::Ptr& service) { service->AddGroup(GetName()); - boost::mutex::scoped_lock lock(m_ServiceGroupMutex); + std::unique_lock lock(m_ServiceGroupMutex); m_Members.insert(service); } void ServiceGroup::RemoveMember(const Service::Ptr& service) { - boost::mutex::scoped_lock lock(m_ServiceGroupMutex); + std::unique_lock lock(m_ServiceGroupMutex); m_Members.erase(service); } diff --git a/lib/icinga/servicegroup.hpp b/lib/icinga/servicegroup.hpp index a4fe132fb..f2d0ab789 100644 --- a/lib/icinga/servicegroup.hpp +++ b/lib/icinga/servicegroup.hpp @@ -32,7 +32,7 @@ public: static void EvaluateObjectRules(const Service::Ptr& service); private: - mutable boost::mutex m_ServiceGroupMutex; + mutable std::mutex m_ServiceGroupMutex; std::set m_Members; static bool EvaluateObjectRule(const Service::Ptr& service, const intrusive_ptr& group); diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index f55a36aaa..4d99db7a1 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -62,7 +62,7 @@ void User::Stop(bool runtimeRemoved) void User::AddGroup(const String& name) { - boost::mutex::scoped_lock lock(m_UserMutex); + std::unique_lock lock(m_UserMutex); Array::Ptr groups = GetGroups(); diff --git a/lib/icinga/user.hpp b/lib/icinga/user.hpp index f91aefd08..14e59c2ce 100644 --- a/lib/icinga/user.hpp +++ b/lib/icinga/user.hpp @@ -36,7 +36,7 @@ protected: void OnConfigLoaded() override; void OnAllConfigLoaded() override; private: - mutable boost::mutex m_UserMutex; + mutable std::mutex m_UserMutex; }; } diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 913882d1c..7702e337c 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -58,7 +58,7 @@ void UserGroup::EvaluateObjectRules(const User::Ptr& user) std::set UserGroup::GetMembers() const { - boost::mutex::scoped_lock lock(m_UserGroupMutex); + std::unique_lock lock(m_UserGroupMutex); return m_Members; } @@ -66,13 +66,13 @@ void UserGroup::AddMember(const User::Ptr& user) { user->AddGroup(GetName()); - boost::mutex::scoped_lock lock(m_UserGroupMutex); + std::unique_lock lock(m_UserGroupMutex); m_Members.insert(user); } void UserGroup::RemoveMember(const User::Ptr& user) { - boost::mutex::scoped_lock lock(m_UserGroupMutex); + std::unique_lock lock(m_UserGroupMutex); m_Members.erase(user); } diff --git a/lib/icinga/usergroup.hpp b/lib/icinga/usergroup.hpp index 169f29c10..e0325b4fc 100644 --- a/lib/icinga/usergroup.hpp +++ b/lib/icinga/usergroup.hpp @@ -32,7 +32,7 @@ public: static void EvaluateObjectRules(const User::Ptr& user); private: - mutable boost::mutex m_UserGroupMutex; + mutable std::mutex m_UserGroupMutex; std::set m_Members; static bool EvaluateObjectRule(const User::Ptr& user, const intrusive_ptr& group); diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index 8344a187e..9aea3db89 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -22,7 +22,7 @@ REGISTER_TYPE(LivestatusListener); static int l_ClientsConnected = 0; static int l_Connections = 0; -static boost::mutex l_ComponentMutex; +static std::mutex l_ComponentMutex; REGISTER_STATSFUNCTION(LivestatusListener, &LivestatusListener::StatsFunc); @@ -119,14 +119,14 @@ void LivestatusListener::Stop(bool runtimeRemoved) int LivestatusListener::GetClientsConnected() { - boost::mutex::scoped_lock lock(l_ComponentMutex); + std::unique_lock lock(l_ComponentMutex); return l_ClientsConnected; } int LivestatusListener::GetConnections() { - boost::mutex::scoped_lock lock(l_ComponentMutex); + std::unique_lock lock(l_ComponentMutex); return l_Connections; } @@ -158,7 +158,7 @@ void LivestatusListener::ServerThreadProc() void LivestatusListener::ClientHandler(const Socket::Ptr& client) { { - boost::mutex::scoped_lock lock(l_ComponentMutex); + std::unique_lock lock(l_ComponentMutex); l_ClientsConnected++; l_Connections++; } @@ -196,7 +196,7 @@ void LivestatusListener::ClientHandler(const Socket::Ptr& client) } { - boost::mutex::scoped_lock lock(l_ComponentMutex); + std::unique_lock lock(l_ComponentMutex); l_ClientsConnected--; } } diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index 04d01f51f..0f9b3dac9 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -30,7 +30,7 @@ using namespace icinga; static int l_ExternalCommands = 0; -static boost::mutex l_QueryMutex; +static std::mutex l_QueryMutex; LivestatusQuery::LivestatusQuery(const std::vector& lines, const String& compat_log_path) : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1), m_ErrorCode(0), @@ -260,7 +260,7 @@ LivestatusQuery::LivestatusQuery(const std::vector& lines, const String& int LivestatusQuery::GetExternalCommands() { - boost::mutex::scoped_lock lock(l_QueryMutex); + std::unique_lock lock(l_QueryMutex); return l_ExternalCommands; } @@ -573,7 +573,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) void LivestatusQuery::ExecuteCommandHelper(const Stream::Ptr& stream) { { - boost::mutex::scoped_lock lock(l_QueryMutex); + std::unique_lock lock(l_QueryMutex); l_ExternalCommands++; } diff --git a/lib/livestatus/logtable.hpp b/lib/livestatus/logtable.hpp index 33c2e33e1..7a8931004 100644 --- a/lib/livestatus/logtable.hpp +++ b/lib/livestatus/logtable.hpp @@ -4,7 +4,6 @@ #define LOGTABLE_H #include "livestatus/historytable.hpp" -#include using namespace icinga; diff --git a/lib/livestatus/statehisttable.hpp b/lib/livestatus/statehisttable.hpp index 9233fd559..db0061575 100644 --- a/lib/livestatus/statehisttable.hpp +++ b/lib/livestatus/statehisttable.hpp @@ -5,7 +5,6 @@ #include "icinga/service.hpp" #include "livestatus/historytable.hpp" -#include using namespace icinga; diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 9ab277f20..294e1dacb 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -365,7 +365,7 @@ void ElasticsearchWriter::Enqueue(const Checkable::Ptr& checkable, const String& const Dictionary::Ptr& fields, double ts) { /* Atomically buffer the data point. */ - boost::mutex::scoped_lock lock(m_DataBufferMutex); + std::unique_lock lock(m_DataBufferMutex); /* Format the timestamps to dynamically select the date datatype inside the index. */ fields->Set("@timestamp", FormatTimestamp(ts)); @@ -398,7 +398,7 @@ void ElasticsearchWriter::FlushTimeout() /* Prevent new data points from being added to the array, there is a * race condition where they could disappear. */ - boost::mutex::scoped_lock lock(m_DataBufferMutex); + std::unique_lock lock(m_DataBufferMutex); /* Flush if there are any data available. */ if (m_DataBuffer.size() > 0) { diff --git a/lib/perfdata/elasticsearchwriter.hpp b/lib/perfdata/elasticsearchwriter.hpp index 45658f574..33bc832e7 100644 --- a/lib/perfdata/elasticsearchwriter.hpp +++ b/lib/perfdata/elasticsearchwriter.hpp @@ -33,7 +33,7 @@ private: WorkQueue m_WorkQueue{10000000, 1}; Timer::Ptr m_FlushTimer; std::vector m_DataBuffer; - boost::mutex m_DataBufferMutex; + std::mutex m_DataBufferMutex; void AddCheckResult(const Dictionary::Ptr& fields, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index f3c789e5e..86cf6aeff 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -398,7 +398,7 @@ void GraphiteWriter::SendMetric(const Checkable::Ptr& checkable, const String& p // do not send \n to debug log msgbuf << "\n"; - boost::mutex::scoped_lock lock(m_StreamMutex); + std::unique_lock lock(m_StreamMutex); if (!GetConnected()) return; diff --git a/lib/perfdata/graphitewriter.hpp b/lib/perfdata/graphitewriter.hpp index 34118ab94..a43ebbce5 100644 --- a/lib/perfdata/graphitewriter.hpp +++ b/lib/perfdata/graphitewriter.hpp @@ -10,7 +10,7 @@ #include "base/timer.hpp" #include "base/workqueue.hpp" #include -#include +#include namespace icinga { @@ -38,7 +38,7 @@ protected: private: Shared::Ptr m_Stream; - boost::mutex m_StreamMutex; + std::mutex m_StreamMutex; WorkQueue m_WorkQueue{10000000, 1}; Timer::Ptr m_ReconnectTimer; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 91a220612..e09a85689 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -118,7 +118,7 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric); { - boost::mutex::scoped_lock lock(m_StreamMutex); + std::unique_lock lock(m_StreamMutex); if (!m_ServiceOutputFile.good()) return; @@ -129,7 +129,7 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C String line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric); { - boost::mutex::scoped_lock lock(m_StreamMutex); + std::unique_lock lock(m_StreamMutex); if (!m_HostOutputFile.good()) return; @@ -144,7 +144,7 @@ void PerfdataWriter::RotateFile(std::ofstream& output, const String& temp_path, Log(LogDebug, "PerfdataWriter") << "Rotating perfdata files."; - boost::mutex::scoped_lock lock(m_StreamMutex); + std::unique_lock lock(m_StreamMutex); if (output.good()) { output.close(); diff --git a/lib/perfdata/perfdatawriter.hpp b/lib/perfdata/perfdatawriter.hpp index 5b6e51ea4..f02ff7226 100644 --- a/lib/perfdata/perfdatawriter.hpp +++ b/lib/perfdata/perfdatawriter.hpp @@ -37,7 +37,7 @@ private: Timer::Ptr m_RotationTimer; std::ofstream m_ServiceOutputFile; std::ofstream m_HostOutputFile; - boost::mutex m_StreamMutex; + std::mutex m_StreamMutex; void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); static Value EscapeMacroMetric(const Value& value); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 3a302544b..a386806fa 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -252,7 +252,7 @@ void ApiListener::Start(bool runtimeCreated) ObjectImpl::Start(runtimeCreated); { - boost::mutex::scoped_lock lock(m_LogLock); + std::unique_lock lock(m_LogLock); OpenLogFile(); } @@ -306,7 +306,7 @@ void ApiListener::Stop(bool runtimeDeleted) << "'" << GetName() << "' stopped."; { - boost::mutex::scoped_lock lock(m_LogLock); + std::unique_lock lock(m_LogLock); CloseLogFile(); RotateLogFile(); } @@ -1048,7 +1048,7 @@ void ApiListener::PersistMessage(const Dictionary::Ptr& message, const ConfigObj pmessage->Set("secobj", secname); } - boost::mutex::scoped_lock lock(m_LogLock); + std::unique_lock lock(m_LogLock); if (m_LogFile) { NetString::WriteStringToStream(m_LogFile, JsonEncode(pmessage)); m_LogMessageCount++; @@ -1347,7 +1347,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) } for (;;) { - boost::mutex::scoped_lock lock(m_LogLock); + std::unique_lock lock(m_LogLock); CloseLogFile(); @@ -1624,7 +1624,7 @@ double ApiListener::CalculateZoneLag(const Endpoint::Ptr& endpoint) bool ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient) { - boost::mutex::scoped_lock lock(m_AnonymousClientsLock); + std::unique_lock lock(m_AnonymousClientsLock); if (GetMaxAnonymousClients() >= 0 && (long)m_AnonymousClients.size() + 1 > (long)GetMaxAnonymousClients()) return false; @@ -1635,31 +1635,31 @@ bool ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient) void ApiListener::RemoveAnonymousClient(const JsonRpcConnection::Ptr& aclient) { - boost::mutex::scoped_lock lock(m_AnonymousClientsLock); + std::unique_lock lock(m_AnonymousClientsLock); m_AnonymousClients.erase(aclient); } std::set ApiListener::GetAnonymousClients() const { - boost::mutex::scoped_lock lock(m_AnonymousClientsLock); + std::unique_lock lock(m_AnonymousClientsLock); return m_AnonymousClients; } void ApiListener::AddHttpClient(const HttpServerConnection::Ptr& aclient) { - boost::mutex::scoped_lock lock(m_HttpClientsLock); + std::unique_lock lock(m_HttpClientsLock); m_HttpClients.insert(aclient); } void ApiListener::RemoveHttpClient(const HttpServerConnection::Ptr& aclient) { - boost::mutex::scoped_lock lock(m_HttpClientsLock); + std::unique_lock lock(m_HttpClientsLock); m_HttpClients.erase(aclient); } std::set ApiListener::GetHttpClients() const { - boost::mutex::scoped_lock lock(m_HttpClientsLock); + std::unique_lock lock(m_HttpClientsLock); return m_HttpClients; } @@ -1718,7 +1718,7 @@ Endpoint::Ptr ApiListener::GetLocalEndpoint() const void ApiListener::UpdateActivePackageStagesCache() { - boost::mutex::scoped_lock lock(m_ActivePackageStagesLock); + std::unique_lock lock(m_ActivePackageStagesLock); for (auto package : ConfigPackageUtility::GetPackages()) { String activeStage; @@ -1740,7 +1740,7 @@ void ApiListener::UpdateActivePackageStagesCache() void ApiListener::CheckApiPackageIntegrity() { - boost::mutex::scoped_lock lock(m_ActivePackageStagesLock); + std::unique_lock lock(m_ActivePackageStagesLock); for (auto package : ConfigPackageUtility::GetPackages()) { String activeStage; @@ -1766,13 +1766,13 @@ void ApiListener::CheckApiPackageIntegrity() void ApiListener::SetActivePackageStage(const String& package, const String& stage) { - boost::mutex::scoped_lock lock(m_ActivePackageStagesLock); + std::unique_lock lock(m_ActivePackageStagesLock); m_ActivePackageStages[package] = stage; } String ApiListener::GetActivePackageStage(const String& package) { - boost::mutex::scoped_lock lock(m_ActivePackageStagesLock); + std::unique_lock lock(m_ActivePackageStagesLock); if (m_ActivePackageStages.find(package) == m_ActivePackageStages.end()) BOOST_THROW_EXCEPTION(ScriptError("Package " + package + " has no active stage.")); @@ -1783,7 +1783,7 @@ String ApiListener::GetActivePackageStage(const String& package) void ApiListener::RemoveActivePackageStage(const String& package) { /* This is the rare occassion when a package has been deleted. */ - boost::mutex::scoped_lock lock(m_ActivePackageStagesLock); + std::unique_lock lock(m_ActivePackageStagesLock); auto it = m_ActivePackageStages.find(package); diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 166414073..21c9eb9fb 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -160,8 +160,8 @@ protected: private: Shared::Ptr m_SSLContext; - mutable boost::mutex m_AnonymousClientsLock; - mutable boost::mutex m_HttpClientsLock; + mutable std::mutex m_AnonymousClientsLock; + mutable std::mutex m_HttpClientsLock; std::set m_AnonymousClients; std::set m_HttpClients; @@ -197,7 +197,7 @@ private: WorkQueue m_RelayQueue; WorkQueue m_SyncQueue{0, 4}; - boost::mutex m_LogLock; + std::mutex m_LogLock; Stream::Ptr m_LogFile; size_t m_LogMessageCount{0}; @@ -247,7 +247,7 @@ private: void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync); /* API Config Packages */ - mutable boost::mutex m_ActivePackageStagesLock; + mutable std::mutex m_ActivePackageStagesLock; std::map m_ActivePackageStages; void UpdateActivePackageStagesCache(); diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 0e5e91a65..6ba0e0ecc 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -86,7 +86,7 @@ void ConfigObjectUtility::RepairPackage(const String& package) void ConfigObjectUtility::CreateStorage() { - boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); + std::unique_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); /* For now, we only use _api as our creation target. */ String package = "_api"; diff --git a/lib/remote/configpackageshandler.cpp b/lib/remote/configpackageshandler.cpp index c1b1a1076..ba0ce89b0 100644 --- a/lib/remote/configpackageshandler.cpp +++ b/lib/remote/configpackageshandler.cpp @@ -63,7 +63,7 @@ void ConfigPackagesHandler::HandleGet( ArrayData results; { - boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); + std::unique_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); for (const String& package : packages) { String activeStage; @@ -111,7 +111,7 @@ void ConfigPackagesHandler::HandlePost( } try { - boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); + std::unique_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); ConfigPackageUtility::CreatePackage(packageName); } catch (const std::exception& ex) { diff --git a/lib/remote/configpackageutility.cpp b/lib/remote/configpackageutility.cpp index f143bfe7c..2289c12af 100644 --- a/lib/remote/configpackageutility.cpp +++ b/lib/remote/configpackageutility.cpp @@ -187,7 +187,7 @@ void ConfigPackageUtility::TryActivateStageCallback(const ProcessResult& pr, con if (pr.ExitStatus == 0) { if (activate) { { - boost::mutex::scoped_lock lock(GetStaticPackageMutex()); + std::unique_lock lock(GetStaticPackageMutex()); ActivateStage(packageName, stageName); } @@ -254,7 +254,7 @@ std::vector ConfigPackageUtility::GetStages(const String& packageName) String ConfigPackageUtility::GetActiveStageFromFile(const String& packageName) { /* Lock the transaction, reading this only happens on startup or when something really is broken. */ - boost::mutex::scoped_lock lock(GetStaticActiveStageMutex()); + std::unique_lock lock(GetStaticActiveStageMutex()); String path = GetPackageDir() + "/" + packageName + "/active-stage"; @@ -274,7 +274,7 @@ String ConfigPackageUtility::GetActiveStageFromFile(const String& packageName) void ConfigPackageUtility::SetActiveStageToFile(const String& packageName, const String& stageName) { - boost::mutex::scoped_lock lock(GetStaticActiveStageMutex()); + std::unique_lock lock(GetStaticActiveStageMutex()); String activeStagePath = GetPackageDir() + "/" + packageName + "/active-stage"; @@ -384,14 +384,14 @@ bool ConfigPackageUtility::ValidateName(const String& name) return (!boost::regex_search(name.GetData(), what, expr)); } -boost::mutex& ConfigPackageUtility::GetStaticPackageMutex() +std::mutex& ConfigPackageUtility::GetStaticPackageMutex() { - static boost::mutex mutex; + static std::mutex mutex; return mutex; } -boost::mutex& ConfigPackageUtility::GetStaticActiveStageMutex() +std::mutex& ConfigPackageUtility::GetStaticActiveStageMutex() { - static boost::mutex mutex; + static std::mutex mutex; return mutex; } diff --git a/lib/remote/configpackageutility.hpp b/lib/remote/configpackageutility.hpp index 5920b628a..7c14e4bda 100644 --- a/lib/remote/configpackageutility.hpp +++ b/lib/remote/configpackageutility.hpp @@ -44,8 +44,8 @@ public: static bool ContainsDotDot(const String& path); static bool ValidateName(const String& name); - static boost::mutex& GetStaticPackageMutex(); - static boost::mutex& GetStaticActiveStageMutex(); + static std::mutex& GetStaticPackageMutex(); + static std::mutex& GetStaticActiveStageMutex(); private: static void CollectDirNames(const String& path, std::vector& dirs); diff --git a/lib/remote/configstageshandler.cpp b/lib/remote/configstageshandler.cpp index a34e35cbc..05fe94a12 100644 --- a/lib/remote/configstageshandler.cpp +++ b/lib/remote/configstageshandler.cpp @@ -128,7 +128,7 @@ void ConfigStagesHandler::HandlePost( if (reload && !activate) BOOST_THROW_EXCEPTION(std::invalid_argument("Parameter 'reload' must be false when 'activate' is false.")); - boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); + std::unique_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); stageName = ConfigPackageUtility::CreateStage(packageName, files); diff --git a/lib/remote/consolehandler.cpp b/lib/remote/consolehandler.cpp index e836f8844..c7a109c53 100644 --- a/lib/remote/consolehandler.cpp +++ b/lib/remote/consolehandler.cpp @@ -20,14 +20,14 @@ using namespace icinga; REGISTER_URLHANDLER("/v1/console", ConsoleHandler); -static boost::mutex l_QueryMutex; +static std::mutex l_QueryMutex; static std::map l_ApiScriptFrames; static Timer::Ptr l_FrameCleanupTimer; -static boost::mutex l_ApiScriptMutex; +static std::mutex l_ApiScriptMutex; static void ScriptFrameCleanupHandler() { - boost::mutex::scoped_lock lock(l_ApiScriptMutex); + std::unique_lock lock(l_ApiScriptMutex); std::vector cleanup_keys; diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp index 155532d5a..e534fc178 100644 --- a/lib/remote/endpoint.cpp +++ b/lib/remote/endpoint.cpp @@ -40,7 +40,7 @@ void Endpoint::AddClient(const JsonRpcConnection::Ptr& client) bool was_master = ApiListener::GetInstance()->IsMaster(); { - boost::mutex::scoped_lock lock(m_ClientsLock); + std::unique_lock lock(m_ClientsLock); m_Clients.insert(client); } @@ -57,7 +57,7 @@ void Endpoint::RemoveClient(const JsonRpcConnection::Ptr& client) bool was_master = ApiListener::GetInstance()->IsMaster(); { - boost::mutex::scoped_lock lock(m_ClientsLock); + std::unique_lock lock(m_ClientsLock); m_Clients.erase(client); Log(LogWarning, "ApiListener") @@ -76,7 +76,7 @@ void Endpoint::RemoveClient(const JsonRpcConnection::Ptr& client) std::set Endpoint::GetClients() const { - boost::mutex::scoped_lock lock(m_ClientsLock); + std::unique_lock lock(m_ClientsLock); return m_Clients; } @@ -87,7 +87,7 @@ Zone::Ptr Endpoint::GetZone() const bool Endpoint::GetConnected() const { - boost::mutex::scoped_lock lock(m_ClientsLock); + std::unique_lock lock(m_ClientsLock); return !m_Clients.empty(); } diff --git a/lib/remote/endpoint.hpp b/lib/remote/endpoint.hpp index 7c490514d..d641c2c6b 100644 --- a/lib/remote/endpoint.hpp +++ b/lib/remote/endpoint.hpp @@ -53,7 +53,7 @@ protected: void OnAllConfigLoaded() override; private: - mutable boost::mutex m_ClientsLock; + mutable std::mutex m_ClientsLock; std::set > m_Clients; intrusive_ptr m_Zone; diff --git a/lib/remote/eventqueue.cpp b/lib/remote/eventqueue.cpp index 3c7504e6c..fd911f0f8 100644 --- a/lib/remote/eventqueue.cpp +++ b/lib/remote/eventqueue.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include using namespace icinga; @@ -21,7 +22,7 @@ EventQueue::EventQueue(String name) bool EventQueue::CanProcessEvent(const String& type) const { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); return m_Types.find(type) != m_Types.end(); } @@ -41,7 +42,7 @@ void EventQueue::ProcessEvent(const Dictionary::Ptr& event) return; } - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); typedef std::pair > kv_pair; for (kv_pair& kv : m_Events) { @@ -53,7 +54,7 @@ void EventQueue::ProcessEvent(const Dictionary::Ptr& event) void EventQueue::AddClient(void *client) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); auto result = m_Events.insert(std::make_pair(client, std::deque())); ASSERT(result.second); @@ -65,14 +66,14 @@ void EventQueue::AddClient(void *client) void EventQueue::RemoveClient(void *client) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Events.erase(client); } void EventQueue::UnregisterIfUnused(const String& name, const EventQueue::Ptr& queue) { - boost::mutex::scoped_lock lock(queue->m_Mutex); + std::unique_lock lock(queue->m_Mutex); if (queue->m_Events.empty()) Unregister(name); @@ -80,19 +81,19 @@ void EventQueue::UnregisterIfUnused(const String& name, const EventQueue::Ptr& q void EventQueue::SetTypes(const std::set& types) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Types = types; } void EventQueue::SetFilter(std::unique_ptr filter) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); m_Filter.swap(filter); } Dictionary::Ptr EventQueue::WaitForEvent(void *client, double timeout) { - boost::mutex::scoped_lock lock(m_Mutex); + std::unique_lock lock(m_Mutex); for (;;) { auto it = m_Events.find(client); @@ -104,7 +105,7 @@ Dictionary::Ptr EventQueue::WaitForEvent(void *client, double timeout) return result; } - if (!m_CV.timed_wait(lock, boost::posix_time::milliseconds(long(timeout * 1000)))) + if (m_CV.wait_for(lock, std::chrono::duration(timeout)) == std::cv_status::timeout) return nullptr; } } diff --git a/lib/remote/eventqueue.hpp b/lib/remote/eventqueue.hpp index e9e5de88f..32bd34a7a 100644 --- a/lib/remote/eventqueue.hpp +++ b/lib/remote/eventqueue.hpp @@ -8,8 +8,7 @@ #include "config/expression.hpp" #include #include -#include -#include +#include #include #include #include @@ -48,8 +47,8 @@ public: private: String m_Name; - mutable boost::mutex m_Mutex; - boost::condition_variable m_CV; + mutable std::mutex m_Mutex; + std::condition_variable m_CV; std::set m_Types; std::unique_ptr m_Filter;