2020-04-23 08:06:14 +10:00
|
|
|
/******************************************************************************
|
|
|
|
_ _
|
|
|
|
| | | |
|
|
|
|
| | ___ | |__ ___
|
|
|
|
| |/ _ \| '_ \ / _ \
|
|
|
|
| | (_) | |_) | (_) |
|
|
|
|
|_|\___/|_.__/ \___/
|
|
|
|
Copyright:
|
|
|
|
Danny Robson, 2020
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "init.hpp"
|
|
|
|
|
|
|
|
#include "log.hpp"
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
using cruft::init::cookie;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
namespace {
|
|
|
|
// Stores the various RAII handlers for any registered functionality that
|
|
|
|
// requires it.
|
|
|
|
struct state {
|
|
|
|
state ()
|
|
|
|
: log (cruft::log::setup_level_reflection ())
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
cruft::parse::enumeration::cookie log;
|
|
|
|
};
|
|
|
|
|
2021-04-09 13:28:49 +10:00
|
|
|
static std::unique_ptr<state> s_state;
|
2020-04-23 08:06:14 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2021-04-09 13:28:49 +10:00
|
|
|
// NOTE: We were using reference counting to cleanup s_state at cookie
|
|
|
|
// destruction time, but for some reason this results in a double-free under
|
|
|
|
// gcc-usan. It's easier to just allow it to live past the useful period and
|
|
|
|
// perform cleanup atexit.
|
2020-04-23 08:06:14 +10:00
|
|
|
static void up (void)
|
|
|
|
{
|
2021-04-09 13:28:49 +10:00
|
|
|
if (!s_state)
|
2020-04-23 08:06:14 +10:00
|
|
|
s_state = std::make_unique<state> ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static void down (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
cookie::cookie () { up (); }
|
|
|
|
cookie::cookie (cookie &&) noexcept { up (); }
|
|
|
|
cookie::cookie (cookie const&) { up (); }
|
|
|
|
cookie& cookie::operator= (cookie &&) noexcept { up (); return *this; }
|
|
|
|
cookie& cookie::operator= (cookie const&) { up (); return *this; }
|
|
|
|
cookie::~cookie () { down (); }
|