simplification workaround homebrew

This commit is contained in:
Klaim (Joël Lamotte) 2025-07-23 13:43:33 +02:00 committed by Joël Lamotte (Klaim)
parent 76b428babc
commit 99d0901dcb
1 changed files with 8 additions and 10 deletions

View File

@ -129,21 +129,18 @@ namespace mamba::logging
constinit std::atomic<bool> message_logger_use_buffer; constinit std::atomic<bool> message_logger_use_buffer;
// NOTE: this looks complicated because it's a workaround `std::vector` implementations // NOTE: this looks complicated because it's a workaround `std::vector` implementations
// which are not `constexpr` (required by c++20), we defer the vector creation to the moment it's needed. // which are not `constexpr` (required by c++20), we defer the vector creation to the moment
// Constexpr constructor is required for a type which is usable in a `constinit` declaration, // it's needed. Constexpr constructor is required for a type which is usable in a
// which is required to avoid the static-initialization-fiasco (at least for initialization). // `constinit` declaration, which is required to avoid the static-initialization-fiasco (at
// least for initialization).
// TODO: once homebrew stl impl has `constexpr` vector, replace al lthis by just `using
// MessageLoggerBuffer = vector<LogRecord>;`
struct MessageLoggerBuffer struct MessageLoggerBuffer
{ {
using buffer = std::vector<LogRecord>; using buffer = std::vector<LogRecord>;
constexpr MessageLoggerBuffer() = default; constexpr MessageLoggerBuffer() = default;
template<class T>
auto push_back(T&& record)
{
return ready_records().push_back(std::forward<T>(record));
}
auto ready_records() -> buffer& auto ready_records() -> buffer&
{ {
if (not records) if (not records)
@ -155,6 +152,7 @@ namespace mamba::logging
std::optional<buffer> records; std::optional<buffer> records;
}; };
constinit util::synchronized_value<MessageLoggerBuffer> message_logger_buffer; constinit util::synchronized_value<MessageLoggerBuffer> message_logger_buffer;
auto auto
@ -191,7 +189,7 @@ namespace mamba::logging
} }
else else
{ {
message_logger_buffer->push_back(std::move(log_record)); message_logger_buffer->ready_records().push_back(std::move(log_record));
} }
} }