mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-03 20:40:17 -05:00
Consistently use Atomic, and not std::atomic
Atomic enforces usage of its only safe constructor, in contrast to std::atomic. "The default-initialized std::atomic<T> does not contain a T object, and its only valid uses are destruction and initialization by std::atomic_init, see LWG issue 2334." -- https://en.cppreference.com/w/cpp/atomic/atomic/atomic
This commit is contained in:
parent
b8aa41caf8
commit
e423fcc68b
21 changed files with 37 additions and 42 deletions
|
|
@ -112,12 +112,12 @@ private:
|
|||
};
|
||||
|
||||
/**
|
||||
* Type alias for std::atomic<T> if possible, otherwise Locked<T> is used as a fallback.
|
||||
* Type alias for Atomic<T> if possible, otherwise Locked<T> is used as a fallback.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
template <typename T>
|
||||
using AtomicOrLocked = std::conditional_t<std::is_trivially_copyable_v<T>, std::atomic<T>, Locked<T>>;
|
||||
using AtomicOrLocked = std::conditional_t<std::is_trivially_copyable_v<T>, Atomic<T>, Locked<T>>;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,10 +85,11 @@ boost::asio::io_context& IoEngine::GetIoContext()
|
|||
return m_IoContext;
|
||||
}
|
||||
|
||||
IoEngine::IoEngine() : m_IoContext(), m_KeepAlive(boost::asio::make_work_guard(m_IoContext)), m_Threads(decltype(m_Threads)::size_type(Configuration::Concurrency * 2u)), m_AlreadyExpiredTimer(m_IoContext)
|
||||
IoEngine::IoEngine() : m_IoContext(), m_KeepAlive(boost::asio::make_work_guard(m_IoContext)),
|
||||
m_Threads(decltype(m_Threads)::size_type(Configuration::Concurrency * 2u)),
|
||||
m_AlreadyExpiredTimer(m_IoContext), m_CpuBoundSemaphore(Configuration::Concurrency * 3u / 2u)
|
||||
{
|
||||
m_AlreadyExpiredTimer.expires_at(boost::posix_time::neg_infin);
|
||||
m_CpuBoundSemaphore.store(Configuration::Concurrency * 3u / 2u);
|
||||
|
||||
for (auto& thread : m_Threads) {
|
||||
thread = std::thread(&IoEngine::RunEventLoop, this);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include "base/lazy-init.hpp"
|
||||
#include "base/logger.hpp"
|
||||
#include "base/shared.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
|
@ -150,7 +150,7 @@ private:
|
|||
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_KeepAlive;
|
||||
std::vector<std::thread> m_Threads;
|
||||
boost::asio::deadline_timer m_AlreadyExpiredTimer;
|
||||
std::atomic_int_fast32_t m_CpuBoundSemaphore;
|
||||
Atomic<int_fast32_t> m_CpuBoundSemaphore;
|
||||
};
|
||||
|
||||
class TerminateIoThread : public std::exception
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef LAZY_INIT
|
||||
#define LAZY_INIT
|
||||
|
||||
#include <atomic>
|
||||
#include "base/atomic.hpp"
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
|
@ -24,7 +24,6 @@ public:
|
|||
inline
|
||||
LazyInit(std::function<T()> initializer = []() { return T(); }) : m_Initializer(std::move(initializer))
|
||||
{
|
||||
m_Underlying.store(nullptr, std::memory_order_release);
|
||||
}
|
||||
|
||||
LazyInit(const LazyInit&) = delete;
|
||||
|
|
@ -64,7 +63,7 @@ public:
|
|||
private:
|
||||
std::function<T()> m_Initializer;
|
||||
std::mutex m_Mutex;
|
||||
std::atomic<T*> m_Underlying;
|
||||
Atomic<T*> m_Underlying {nullptr};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ REGISTER_TYPE(Logger);
|
|||
std::set<Logger::Ptr> Logger::m_Loggers;
|
||||
std::mutex Logger::m_Mutex;
|
||||
bool Logger::m_ConsoleLogEnabled = true;
|
||||
std::atomic<bool> Logger::m_EarlyLoggingEnabled (true);
|
||||
Atomic<bool> Logger::m_EarlyLoggingEnabled (true);
|
||||
bool Logger::m_TimestampEnabled = true;
|
||||
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
|
||||
std::mutex Logger::m_UpdateMinLogSeverityMutex;
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ private:
|
|||
static std::mutex m_Mutex;
|
||||
static std::set<Logger::Ptr> m_Loggers;
|
||||
static bool m_ConsoleLogEnabled;
|
||||
static std::atomic<bool> m_EarlyLoggingEnabled;
|
||||
static Atomic<bool> m_EarlyLoggingEnabled;
|
||||
static bool m_TimestampEnabled;
|
||||
static LogSeverity m_ConsoleLogSeverity;
|
||||
static std::mutex m_UpdateMinLogSeverityMutex;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
#define NAMESPACE_H
|
||||
|
||||
#include "base/i2-base.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/object.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/shared-object.hpp"
|
||||
#include "base/value.hpp"
|
||||
#include "base/debuginfo.hpp"
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
|
@ -95,7 +95,7 @@ private:
|
|||
std::map<String, NamespaceValue> m_Data;
|
||||
mutable std::shared_timed_mutex m_DataMutex;
|
||||
bool m_ConstValues;
|
||||
std::atomic<bool> m_Frozen;
|
||||
Atomic<bool> m_Frozen;
|
||||
};
|
||||
|
||||
Namespace::Iterator begin(const Namespace::Ptr& x);
|
||||
|
|
|
|||
|
|
@ -27,11 +27,6 @@ static Timer::Ptr l_ObjectCountTimer;
|
|||
*/
|
||||
Object::Object()
|
||||
{
|
||||
m_References.store(0);
|
||||
|
||||
#ifdef I2_DEBUG
|
||||
m_LockOwner.store(decltype(m_LockOwner.load())());
|
||||
#endif /* I2_DEBUG */
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
#define OBJECT_H
|
||||
|
||||
#include "base/i2-base.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/debug.hpp"
|
||||
#include "base/intrusive-ptr.hpp"
|
||||
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
|
|
@ -193,11 +193,11 @@ private:
|
|||
Object(const Object& other) = delete;
|
||||
Object& operator=(const Object& rhs) = delete;
|
||||
|
||||
mutable std::atomic<uint_fast64_t> m_References;
|
||||
mutable Atomic<uint_fast64_t> m_References {0};
|
||||
mutable std::recursive_mutex m_Mutex;
|
||||
|
||||
#ifdef I2_DEBUG
|
||||
mutable std::atomic<std::thread::id> m_LockOwner;
|
||||
mutable Atomic<std::thread::id> m_LockOwner {std::thread::id()};
|
||||
mutable size_t m_LockCount = 0;
|
||||
#endif /* I2_DEBUG */
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
#define TLSSTREAM_H
|
||||
|
||||
#include "base/i2-base.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/shared.hpp"
|
||||
#include "base/socket.hpp"
|
||||
#include "base/stream.hpp"
|
||||
#include "base/tlsutility.hpp"
|
||||
#include "base/fifo.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <boost/asio/buffered_stream.hpp>
|
||||
|
|
@ -30,7 +30,6 @@ public:
|
|||
template<class... Args>
|
||||
SeenStream(Args&&... args) : ARS(std::forward<Args>(args)...)
|
||||
{
|
||||
m_Seen.store(nullptr);
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
|
|
@ -53,7 +52,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::atomic<double*> m_Seen;
|
||||
Atomic<double*> m_Seen {nullptr};
|
||||
};
|
||||
|
||||
struct UnbufferedAsioTlsStreamParams
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
std::atomic<int> WorkQueue::m_NextID(1);
|
||||
Atomic<int> WorkQueue::m_NextID (1);
|
||||
boost::thread_specific_ptr<WorkQueue *> l_ThreadWorkQueue;
|
||||
|
||||
WorkQueue::WorkQueue(size_t maxItems, int threadCount, LogSeverity statsLogLevel)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#define WORKQUEUE_H
|
||||
|
||||
#include "base/i2-base.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/timer.hpp"
|
||||
#include "base/ringbuffer.hpp"
|
||||
#include "base/logger.hpp"
|
||||
|
|
@ -13,7 +14,6 @@
|
|||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
#include <atomic>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
@ -122,7 +122,7 @@ protected:
|
|||
private:
|
||||
int m_ID;
|
||||
String m_Name;
|
||||
static std::atomic<int> m_NextID;
|
||||
static Atomic<int> m_NextID;
|
||||
int m_ThreadCount;
|
||||
bool m_Spawned{false};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
#include "config/i2-config.hpp"
|
||||
#include "config/expression.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/debuginfo.hpp"
|
||||
#include "base/shared-object.hpp"
|
||||
#include "base/type.hpp"
|
||||
#include <unordered_map>
|
||||
#include <atomic>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
@ -104,7 +104,7 @@ private:
|
|||
bool m_IgnoreOnError;
|
||||
DebugInfo m_DebugInfo;
|
||||
Dictionary::Ptr m_Scope;
|
||||
std::atomic<bool> m_HasMatches;
|
||||
Atomic<bool> m_HasMatches;
|
||||
|
||||
static TypeMap m_Types;
|
||||
static RuleMap m_Rules;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "config/objectrule.hpp"
|
||||
#include "config/configcompiler.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/configtype.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/convert.hpp"
|
||||
|
|
@ -21,7 +22,6 @@
|
|||
#include "base/function.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <atomic>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
|
@ -447,7 +447,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||
int itemsCount {0};
|
||||
|
||||
for (auto& type : Type::GetConfigTypesSortedByLoadDependencies()) {
|
||||
std::atomic<int> committed_items(0);
|
||||
Atomic committed_items (0);
|
||||
|
||||
{
|
||||
auto items (itemsByType.find(type.get()));
|
||||
|
|
@ -493,7 +493,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
|
|||
#endif /* I2_DEBUG */
|
||||
|
||||
for (auto& type : Type::GetConfigTypesSortedByLoadDependencies()) {
|
||||
std::atomic<int> notified_items(0);
|
||||
Atomic notified_items (0);
|
||||
|
||||
{
|
||||
auto items (itemsByType.find(type.get()));
|
||||
|
|
|
|||
|
|
@ -390,4 +390,4 @@ bool ScheduledDowntime::AllConfigIsLoaded()
|
|||
return m_AllConfigLoaded.load();
|
||||
}
|
||||
|
||||
std::atomic<bool> ScheduledDowntime::m_AllConfigLoaded (false);
|
||||
Atomic<bool> ScheduledDowntime::m_AllConfigLoaded (false);
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#define SCHEDULEDDOWNTIME_H
|
||||
|
||||
#include "icinga/i2-icinga.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "icinga/scheduleddowntime-ti.hpp"
|
||||
#include "icinga/checkable.hpp"
|
||||
#include <atomic>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
@ -49,7 +49,7 @@ private:
|
|||
void CreateNextDowntime();
|
||||
void RemoveObsoleteDowntimes();
|
||||
|
||||
static std::atomic<bool> m_AllConfigLoaded;
|
||||
static Atomic<bool> m_AllConfigLoaded;
|
||||
|
||||
static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
|
||||
static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter = false);
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
#include "icinga/service.hpp"
|
||||
#include "icinga/downtime.hpp"
|
||||
#include "remote/messageorigin.hpp"
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
|
@ -250,7 +250,7 @@ private:
|
|||
// syncronization to m_Rcon within the IcingaDB feature itself.
|
||||
Locked<RedisConnection::Ptr> m_RconLocked;
|
||||
std::unordered_map<ConfigType*, RedisConnection::Ptr> m_Rcons;
|
||||
std::atomic_size_t m_PendingRcons;
|
||||
Atomic<size_t> m_PendingRcons {0};
|
||||
|
||||
struct {
|
||||
DumpedGlobals CustomVar, ActionUrl, NotesUrl, IconImage, DependencyGroup;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "perfdata/influxdbcommonwriter-ti.hpp"
|
||||
#include "icinga/service.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include "base/configobject.hpp"
|
||||
#include "base/perfdatavalue.hpp"
|
||||
#include "base/tcpsocket.hpp"
|
||||
|
|
@ -14,7 +15,7 @@
|
|||
#include "remote/url.hpp"
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
|
||||
namespace icinga
|
||||
|
|
@ -51,7 +52,7 @@ private:
|
|||
Timer::Ptr m_FlushTimer;
|
||||
WorkQueue m_WorkQueue{10000000, 1};
|
||||
std::vector<String> m_DataBuffer;
|
||||
std::atomic_size_t m_DataBufferSize{0};
|
||||
Atomic<size_t> m_DataBufferSize {0};
|
||||
|
||||
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
||||
void SendMetric(const Checkable::Ptr& checkable, const Dictionary::Ptr& tmpl,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
std::atomic<bool> ApiListener::m_UpdatedObjectAuthority (false);
|
||||
Atomic<bool> ApiListener::m_UpdatedObjectAuthority (false);
|
||||
|
||||
void ApiListener::UpdateObjectAuthority()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
#include "base/tlsstream.hpp"
|
||||
#include "base/threadpool.hpp"
|
||||
#include "base/wait-group.hpp"
|
||||
#include <atomic>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
|
|
@ -192,7 +191,7 @@ private:
|
|||
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
|
||||
|
||||
static ApiListener::Ptr m_Instance;
|
||||
static std::atomic<bool> m_UpdatedObjectAuthority;
|
||||
static Atomic<bool> m_UpdatedObjectAuthority;
|
||||
|
||||
boost::signals2::signal<void()> m_OnListenerShutdown;
|
||||
StoppableWaitGroup::Ptr m_ListenerWaitGroup = new StoppableWaitGroup();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#ifndef CONFIGSTAGESHANDLER_H
|
||||
#define CONFIGSTAGESHANDLER_H
|
||||
|
||||
#include "base/atomic.hpp"
|
||||
#include "remote/httphandler.hpp"
|
||||
|
||||
namespace icinga
|
||||
|
|
|
|||
Loading…
Reference in a new issue