log: workaround mingw's lack of once_flag
This commit is contained in:
parent
d0d9c3a676
commit
44abca88d6
@ -43,7 +43,9 @@ cruft::log::needs_break (level_t level)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static std::once_flag s_sink_init;
|
||||
// mingw#xxx: MinGW doesn't have once_flag so we just use an atomic bool.
|
||||
// Pray that multiple threads don't run into an issue here.
|
||||
static std::atomic<bool> s_sink_init;
|
||||
static std::unique_ptr<cruft::log::sink::base> s_default_sink;
|
||||
|
||||
|
||||
@ -60,11 +62,12 @@ cruft::log::default_sink (std::unique_ptr<sink::base> value)
|
||||
cruft::log::sink::base&
|
||||
cruft::log::default_sink ()
|
||||
{
|
||||
std::call_once (s_sink_init, [&] () {
|
||||
if (unlikely (!s_sink_init)) {
|
||||
default_sink (
|
||||
std::make_unique<sink::console> (PACKAGE_NAME)
|
||||
);
|
||||
});
|
||||
s_sink_init = true;
|
||||
}
|
||||
|
||||
return *s_default_sink;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user