@@ -129,21 +129,18 @@ namespace mamba::logging
129
129
constinit std::atomic<bool > message_logger_use_buffer;
130
130
131
131
// NOTE: this looks complicated because it's a workaround `std::vector` implementations
132
- // which are not `constexpr` (required by c++20), we defer the vector creation to the moment it's needed.
133
- // Constexpr constructor is required for a type which is usable in a `constinit` declaration,
134
- // which is required to avoid the static-initialization-fiasco (at least for initialization).
132
+ // which are not `constexpr` (required by c++20), we defer the vector creation to the moment
133
+ // it's needed. Constexpr constructor is required for a type which is usable in a
134
+ // `constinit` declaration, which is required to avoid the static-initialization-fiasco (at
135
+ // least for initialization).
136
+ // TODO: once homebrew stl impl has `constexpr` vector, replace al lthis by just `using
137
+ // MessageLoggerBuffer = vector<LogRecord>;`
135
138
struct MessageLoggerBuffer
136
139
{
137
140
using buffer = std::vector<LogRecord>;
138
141
139
142
constexpr MessageLoggerBuffer () = default;
140
143
141
- template <class T >
142
- auto push_back (T&& record)
143
- {
144
- return ready_records ().push_back (std::forward<T>(record));
145
- }
146
-
147
144
auto ready_records () -> buffer&
148
145
{
149
146
if (not records)
@@ -155,6 +152,7 @@ namespace mamba::logging
155
152
156
153
std::optional<buffer> records;
157
154
};
155
+
158
156
constinit util::synchronized_value<MessageLoggerBuffer> message_logger_buffer;
159
157
160
158
auto
@@ -191,7 +189,7 @@ namespace mamba::logging
191
189
}
192
190
else
193
191
{
194
- message_logger_buffer->push_back (std::move (log_record));
192
+ message_logger_buffer->ready_records (). push_back (std::move (log_record));
195
193
}
196
194
}
197
195
0 commit comments