Cycles: Fix static initialization order fiasco

Initialization order of global stats and node types was not strictly
defined and it was possible to have node types initialized first and
stats after that. This will zero out memory which was allocated from
the statistics causing assert failure when de-initializing node types.
This commit is contained in:
Sergey Sharybin 2016-10-24 13:43:55 +02:00
parent f55221e0a1
commit f0adb875cf
2 changed files with 4 additions and 1 deletions

View File

@ -19,7 +19,7 @@
CCL_NAMESPACE_BEGIN
static Stats global_stats;
static Stats global_stats(Stats::static_init);
/* Internal API. */

View File

@ -23,7 +23,10 @@ CCL_NAMESPACE_BEGIN
class Stats {
public:
enum static_init_t { static_init = 0 };
Stats() : mem_used(0), mem_peak(0) {}
explicit Stats(static_init_t) {}
void mem_alloc(size_t size) {
atomic_add_z(&mem_used, size);