Made the statistics print atexit

Fixed some statistics and made them automatically print atexit.
This commit is contained in:
Matthew Parkinson
2019-05-15 17:21:43 +01:00
parent 48416e3241
commit b8bcfc0798
4 changed files with 45 additions and 6 deletions

View File

@@ -13,12 +13,20 @@ namespace snmalloc
class Singleton
{
public:
inline static Object& get()
/**
* If argument is non-null, then it is assigned the value
* true, if this is the first call to get.
* At most one call will be first.
*/
inline static Object& get(bool* first = nullptr)
{
static std::atomic_flag flag;
static std::atomic<bool> initialised;
static Object obj;
// If defined should be initially false;
assert(first == nullptr || *first == false);
if (!initialised.load(std::memory_order_acquire))
{
FlagLock lock(flag);
@@ -26,6 +34,8 @@ namespace snmalloc
{
obj = init();
initialised.store(true, std::memory_order_release);
if (first != nullptr)
*first = true;
}
}
return obj;