From 56ae875861ab260b80a030f50c4aff9f9dc8fff0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:32:39 +0200 Subject: Adding upstream version 2.14.2. Signed-off-by: Daniel Baumann --- lib/remote/configobjectslock.hpp | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/remote/configobjectslock.hpp (limited to 'lib/remote/configobjectslock.hpp') diff --git a/lib/remote/configobjectslock.hpp b/lib/remote/configobjectslock.hpp new file mode 100644 index 0000000..ee90981 --- /dev/null +++ b/lib/remote/configobjectslock.hpp @@ -0,0 +1,72 @@ +/* Icinga 2 | (c) 2023 Icinga GmbH | GPLv2+ */ + +#pragma once + +#include + +#ifndef _WIN32 +#include +#include +#include +#endif /* _WIN32 */ + +namespace icinga +{ + +#ifdef _WIN32 + +class ConfigObjectsSharedLock +{ +public: + inline ConfigObjectsSharedLock(std::try_to_lock_t) + { + } + + constexpr explicit operator bool() const + { + return true; + } +}; + +#else /* _WIN32 */ + +/** + * Waits until all ConfigObjects*Lock-s have vanished. For its lifetime disallows such. + * Keep an instance alive during reload to forbid runtime config changes! + * This way Icinga reads a consistent config which doesn't suddenly get runtime-changed. + * + * @ingroup remote + */ +class ConfigObjectsExclusiveLock +{ +public: + ConfigObjectsExclusiveLock(); + +private: + boost::interprocess::scoped_lock m_Lock; +}; + +/** + * Waits until the only ConfigObjectsExclusiveLock has vanished (if any). For its lifetime disallows such. + * Keep an instance alive during runtime config changes to delay a reload (if any)! + * This way Icinga reads a consistent config which doesn't suddenly get runtime-changed. + * + * @ingroup remote + */ +class ConfigObjectsSharedLock +{ +public: + ConfigObjectsSharedLock(std::try_to_lock_t); + + inline explicit operator bool() const + { + return m_Lock.owns(); + } + +private: + boost::interprocess::sharable_lock m_Lock; +}; + +#endif /* _WIN32 */ + +} -- cgit v1.2.3