DaemonCommand: make the atomics a bit more atomic

Just to be sure.

refs #5230
This commit is contained in:
Alexander A. Klimov 2019-07-16 11:28:20 +02:00
parent 4ee9ac16b4
commit c385355c38
3 changed files with 52 additions and 8 deletions

View File

@ -15,6 +15,7 @@ set(base_SOURCES
i2-base.hpp i2-base.hpp
application.cpp application.hpp application-ti.hpp application-version.cpp application-environment.cpp application.cpp application.hpp application-ti.hpp application-version.cpp application-environment.cpp
array.cpp array.hpp array-script.cpp array.cpp array.hpp array-script.cpp
atomic.hpp
base64.cpp base64.hpp base64.cpp base64.hpp
boolean.cpp boolean.hpp boolean-script.cpp boolean.cpp boolean.hpp boolean-script.cpp
configobject.cpp configobject.hpp configobject-ti.hpp configobject-script.cpp configobject.cpp configobject.hpp configobject-ti.hpp configobject-script.cpp

43
lib/base/atomic.hpp Normal file
View File

@ -0,0 +1,43 @@
/* Icinga 2 | (c) 2019 Icinga GmbH | GPLv2+ */
#ifndef ATOMIC_H
#define ATOMIC_H
#include <atomic>
namespace icinga
{
/**
* Extends std::atomic with an atomic constructor.
*
* @ingroup base
*/
template<class T>
class Atomic : public std::atomic<T> {
public:
/**
* Like std::atomic#atomic, but operates atomically
*
* @param desired Initial value
*/
inline Atomic(T desired)
{
this->store(desired);
}
/**
* Like std::atomic#atomic, but operates atomically
*
* @param desired Initial value
* @param order Initial store operation's memory order
*/
inline Atomic(T desired, std::memory_order order)
{
this->store(desired, order);
}
};
}
#endif /* ATOMIC_H */

View File

@ -7,6 +7,7 @@
#include "config/configcompiler.hpp" #include "config/configcompiler.hpp"
#include "config/configcompilercontext.hpp" #include "config/configcompilercontext.hpp"
#include "config/configitembuilder.hpp" #include "config/configitembuilder.hpp"
#include "base/atomic.hpp"
#include "base/defer.hpp" #include "base/defer.hpp"
#include "base/logger.hpp" #include "base/logger.hpp"
#include "base/application.hpp" #include "base/application.hpp"
@ -17,7 +18,6 @@
#include "base/scriptglobal.hpp" #include "base/scriptglobal.hpp"
#include "base/context.hpp" #include "base/context.hpp"
#include "config.h" #include "config.h"
#include <atomic>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
@ -186,7 +186,7 @@ std::vector<String> DaemonCommand::GetArgumentSuggestions(const String& argument
pid_t l_UmbrellaPid = 0; pid_t l_UmbrellaPid = 0;
// Whether the umbrella process allowed us to continue working beyond config validation // Whether the umbrella process allowed us to continue working beyond config validation
static std::atomic<bool> l_AllowedToWork (false); static Atomic<bool> l_AllowedToWork (false);
#endif /* _WIN32 */ #endif /* _WIN32 */
/** /**
@ -284,19 +284,19 @@ static const sigset_t l_UnixWorkerSignals = ([]() -> sigset_t {
})(); })();
// The PID of the seemless worker currently being started by StartUnixWorker() // The PID of the seemless worker currently being started by StartUnixWorker()
static std::atomic<pid_t> l_CurrentlyStartingUnixWorkerPid (-1); static Atomic<pid_t> l_CurrentlyStartingUnixWorkerPid (-1);
// The state of the seemless worker currently being started by StartUnixWorker() // The state of the seemless worker currently being started by StartUnixWorker()
static std::atomic<UnixWorkerState> l_CurrentlyStartingUnixWorkerState (UnixWorkerState::Pending); static Atomic<UnixWorkerState> l_CurrentlyStartingUnixWorkerState (UnixWorkerState::Pending);
// The last temination signal we received // The last temination signal we received
static std::atomic<int> l_TermSignal (-1); static Atomic<int> l_TermSignal (-1);
// Whether someone requested to re-load config (and we didn't handle that request, yet) // Whether someone requested to re-load config (and we didn't handle that request, yet)
static std::atomic<bool> l_RequestedReload (false); static Atomic<bool> l_RequestedReload (false);
// Whether someone requested to re-open logs (and we didn't handle that request, yet) // Whether someone requested to re-open logs (and we didn't handle that request, yet)
static std::atomic<bool> l_RequestedReopenLogs (false); static Atomic<bool> l_RequestedReopenLogs (false);
/** /**
* Umbrella process' signal handlers * Umbrella process' signal handlers
@ -374,7 +374,7 @@ static void WorkerSignalHandler(int num, siginfo_t *info, void*)
#ifdef HAVE_SYSTEMD #ifdef HAVE_SYSTEMD
// When we last notified the watchdog. // When we last notified the watchdog.
static std::atomic<double> l_LastNotifiedWatchdog (0); static Atomic<double> l_LastNotifiedWatchdog (0);
/** /**
* Notify the watchdog if not notified during the last 2.5s. * Notify the watchdog if not notified during the last 2.5s.