Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/base/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace icinga
template<class T>
class Atomic : public std::atomic<T> {
public:
using std::atomic<T>::operator=;

/**
* The only safe constructor of std::atomic#atomic
*
Expand Down Expand Up @@ -85,6 +87,12 @@ template<typename T>
class Locked
{
public:
Locked() = default;

Locked(T desired) : m_Value(std::move(desired))
{
}

inline T load() const
{
std::unique_lock<std::mutex> lock(m_Mutex);
Expand All @@ -105,12 +113,12 @@ class Locked
};

/**
* 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>>;

}

Expand Down
5 changes: 3 additions & 2 deletions lib/base/io-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
auto& ie (IoEngine::Get());
auto freeSlots (ie.m_CpuBoundSemaphore.load());

while (freeSlots > 0u) {

Check warning on line 81 in lib/base/io-engine.cpp

View workflow job for this annotation

GitHub Actions / alpine:bash

comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]

Check warning on line 81 in lib/base/io-engine.cpp

View workflow job for this annotation

GitHub Actions / debian:11 (linux/386)

comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]

Check warning on line 81 in lib/base/io-engine.cpp

View workflow job for this annotation

GitHub Actions / debian:12 (linux/386)

comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
// If ie.m_CpuBoundSemaphore was changed after the last load,
// compare_exchange_weak() will load its latest value into freeSlots for us to retry until...
if (ie.m_CpuBoundSemaphore.compare_exchange_weak(freeSlots, freeSlots - 1u)) {
Expand Down Expand Up @@ -142,9 +142,10 @@
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))
IoEngine::IoEngine() : m_IoContext(), m_KeepAlive(boost::asio::make_work_guard(m_IoContext)),
m_Threads(decltype(m_Threads)::size_type(Configuration::Concurrency * 2u)),
m_CpuBoundSemaphore(Configuration::Concurrency * 3u / 2u)
{
m_CpuBoundSemaphore.store(Configuration::Concurrency * 3u / 2u);

for (auto& thread : m_Threads) {
thread = std::thread(&IoEngine::RunEventLoop, this);
Expand Down
4 changes: 2 additions & 2 deletions lib/base/io-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/lazy-init.hpp"
#include "base/logger.hpp"
#include "base/shared.hpp"
#include <atomic>
#include <cstdint>
#include <exception>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -152,7 +152,7 @@ class IoEngine
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_KeepAlive;
std::vector<std::thread> m_Threads;

std::atomic_uint_fast32_t m_CpuBoundSemaphore;
Atomic<int_fast32_t> m_CpuBoundSemaphore;
std::mutex m_CpuBoundWaitingMutex;
std::vector<std::pair<boost::asio::io_context::strand, Shared<AsioConditionVariable>::Ptr>> m_CpuBoundWaiting;
};
Expand Down
5 changes: 2 additions & 3 deletions lib/base/lazy-init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef LAZY_INIT
#define LAZY_INIT

#include <atomic>
#include "base/atomic.hpp"
#include <functional>
#include <mutex>
#include <utility>
Expand All @@ -25,7 +25,6 @@ class LazyInit
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;
Expand Down Expand Up @@ -65,7 +64,7 @@ class LazyInit
private:
std::function<T()> m_Initializer;
std::mutex m_Mutex;
std::atomic<T*> m_Underlying;
Atomic<T*> m_Underlying {nullptr};
};

}
Expand Down
2 changes: 1 addition & 1 deletion lib/base/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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;
Expand Down
2 changes: 1 addition & 1 deletion lib/base/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Logger : public ObjectImpl<Logger>
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;
Expand Down
4 changes: 2 additions & 2 deletions lib/base/namespace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,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>
Expand Down Expand Up @@ -96,7 +96,7 @@ class Namespace final : public Object
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);
Expand Down
5 changes: 0 additions & 5 deletions lib/base/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,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 */
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/base/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,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>
Expand Down Expand Up @@ -194,11 +194,11 @@ class Object
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 */

Expand Down
5 changes: 2 additions & 3 deletions lib/base/tlsstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,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 <variant>
Expand All @@ -32,7 +32,6 @@ class SeenStream : public ARS
template<class... Args>
SeenStream(Args&&... args) : ARS(std::forward<Args>(args)...)
{
m_Seen.store(nullptr);
}

template<class... Args>
Expand All @@ -55,7 +54,7 @@ class SeenStream : public ARS
}

private:
std::atomic<double*> m_Seen;
Atomic<double*> m_Seen {nullptr};
};

struct UnbufferedAsioTlsStreamParams
Expand Down
2 changes: 1 addition & 1 deletion lib/base/workqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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)
Expand Down
4 changes: 2 additions & 2 deletions lib/base/workqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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"
Expand All @@ -14,7 +15,6 @@
#include <mutex>
#include <queue>
#include <deque>
#include <atomic>

namespace icinga
{
Expand Down Expand Up @@ -122,7 +122,7 @@ class WorkQueue
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};

Expand Down
4 changes: 2 additions & 2 deletions lib/config/applyrule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,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
{
Expand Down Expand Up @@ -105,7 +105,7 @@ class ApplyRule : public SharedObject
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;
Expand Down
6 changes: 3 additions & 3 deletions lib/config/configitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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"
Expand All @@ -22,7 +23,6 @@
#include "base/function.hpp"
#include "base/utility.hpp"
#include <boost/algorithm/string/join.hpp>
#include <atomic>
#include <sstream>
#include <fstream>
#include <algorithm>
Expand Down Expand Up @@ -450,7 +450,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
#endif /* I2_DEBUG */

for (auto& type : Type::GetConfigTypesSortedByLoadDependencies()) {
std::atomic<int> committed_items(0);
Atomic committed_items (0);

{
auto items (itemsByType.find(type.get()));
Expand Down Expand Up @@ -496,7 +496,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()));
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/scheduleddowntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,4 @@ bool ScheduledDowntime::AllConfigIsLoaded()
return m_AllConfigLoaded.load();
}

std::atomic<bool> ScheduledDowntime::m_AllConfigLoaded (false);
Atomic<bool> ScheduledDowntime::m_AllConfigLoaded (false);
4 changes: 2 additions & 2 deletions lib/icinga/scheduleddowntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,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
{
Expand Down Expand Up @@ -50,7 +50,7 @@ class ScheduledDowntime final : public ObjectImpl<ScheduledDowntime>
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);
Expand Down
4 changes: 2 additions & 2 deletions lib/icingadb/icingadb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,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>
Expand Down Expand Up @@ -261,7 +261,7 @@ class IcingaDB : public ObjectImpl<IcingaDB>
// 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;
Expand Down
5 changes: 3 additions & 2 deletions lib/perfdata/influxdbcommonwriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#define INFLUXDBCOMMONWRITER_H

#include "perfdata/influxdbcommonwriter-ti.hpp"
#include "base/atomic.hpp"
#include "icinga/checkable.hpp"
#include "base/configobject.hpp"
#include "base/perfdatavalue.hpp"
#include "base/workqueue.hpp"
#include "remote/url.hpp"
#include "perfdata/perfdatawriterconnection.hpp"
#include <atomic>
#include <cstddef>

namespace icinga
{
Expand Down Expand Up @@ -49,7 +50,7 @@ class InfluxdbCommonWriter : public ObjectImpl<InfluxdbCommonWriter>
std::atomic_bool m_FlushTimerInQueue{false};
WorkQueue m_WorkQueue{10000000, 1};
std::vector<String> m_DataBuffer;
std::atomic_size_t m_DataBufferSize{0};
Atomic<size_t> m_DataBufferSize {0};
Shared<boost::asio::ssl::context>::Ptr m_SslContext;
PerfdataWriterConnection::Ptr m_Connection;

Expand Down
2 changes: 1 addition & 1 deletion lib/remote/apilistener-authority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace icinga;

std::atomic<bool> ApiListener::m_UpdatedObjectAuthority (false);
Atomic<bool> ApiListener::m_UpdatedObjectAuthority (false);

void ApiListener::UpdateObjectAuthority()
{
Expand Down
3 changes: 1 addition & 2 deletions lib/remote/apilistener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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>
Expand Down Expand Up @@ -194,7 +193,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
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();
Expand Down
1 change: 1 addition & 0 deletions lib/remote/configstageshandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef CONFIGSTAGESHANDLER_H
#define CONFIGSTAGESHANDLER_H

#include "base/atomic.hpp"
#include "remote/httphandler.hpp"

namespace icinga
Expand Down
Loading
Loading