File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -546,12 +546,7 @@ namespace mamba::util
546
546
// /////////////////////////////////////////////////////////////////////////////////////////
547
547
548
548
template <std::default_initializable T, Mutex M>
549
- constexpr synchronized_value<T, M>::synchronized_value(
550
- ) noexcept (std::is_nothrow_default_constructible_v<T>)
551
- {
552
- // NOTE: non-defaulted because of homebrew/clang compiler not liking the defaulted version
553
- // for some reason
554
- }
549
+ constexpr synchronized_value<T, M>::synchronized_value() noexcept (std::is_nothrow_default_constructible_v<T>) = default ;
555
550
556
551
template <std::default_initializable T, Mutex M>
557
552
synchronized_value<T, M>::synchronized_value(T value) noexcept
Original file line number Diff line number Diff line change @@ -128,7 +128,33 @@ namespace mamba::logging
128
128
{
129
129
constinit std::atomic<bool > message_logger_use_buffer;
130
130
131
- using MessageLoggerBuffer = std::vector<LogRecord>;
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).
135
+ struct MessageLoggerBuffer
136
+ {
137
+ using buffer = std::vector<LogRecord>;
138
+
139
+ constexpr MessageLoggerBuffer () = default;
140
+
141
+ template <class T >
142
+ auto push_back (T&& record)
143
+ {
144
+ return ready_records ().push_back (std::forward<T>(record));
145
+ }
146
+
147
+ auto ready_records () -> buffer&
148
+ {
149
+ if (not records)
150
+ {
151
+ records = buffer{};
152
+ }
153
+ return *records;
154
+ }
155
+
156
+ std::optional<buffer> records;
157
+ };
132
158
constinit util::synchronized_value<MessageLoggerBuffer> message_logger_buffer;
133
159
134
160
auto
@@ -193,8 +219,8 @@ namespace mamba::logging
193
219
194
220
void MessageLogger::print_buffer (std::ostream& /* ostream*/ )
195
221
{
196
- MessageLoggerBuffer tmp;
197
- message_logger_buffer->swap (tmp);
222
+ MessageLoggerBuffer::buffer tmp;
223
+ message_logger_buffer->ready_records (). swap (tmp);
198
224
199
225
for (auto & log_record : tmp)
200
226
{
You can’t perform that action at this time.
0 commit comments