From 3f14e649b58cc5e3d0997e1af8b18e6440e73148 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 23 Sep 2017 07:44:52 -0400 Subject: [PATCH] Internals: Use singleton in place of global --- include/verilated_vcd_c.cpp | 15 +++++---------- include/verilated_vcd_c.h | 6 +++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 0b134b249..f7e115e52 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -46,11 +46,6 @@ # define O_NONBLOCK 0 #endif -//============================================================================= -// Global - -VerilatedVcd::VcdVec VerilatedVcd::s_vcdVecp; ///< List of all created traces - //============================================================================= // VerilatedVcdCallInfo /// Internal callback routines for each module being traced. @@ -121,7 +116,7 @@ void VerilatedVcd::open (const char* filename) { // Set member variables m_filename = filename; - s_vcdVecp.push_back(this); + singleton().s_vcdVecp.push_back(this); // SPDIFF_OFF // Set callback so an early exit will flush us @@ -234,8 +229,8 @@ VerilatedVcd::~VerilatedVcd() { deleteNameMap(); if (m_filep && m_fileNewed) { delete m_filep; m_filep = NULL; } // Remove from list of traces - VcdVec::iterator pos = find(s_vcdVecp.begin(), s_vcdVecp.end(), this); - if (pos != s_vcdVecp.end()) { s_vcdVecp.erase(pos); } + VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), this); + if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); } } void VerilatedVcd::closePrev () { @@ -647,8 +642,8 @@ void VerilatedVcd::dumpDone () { // Static members void VerilatedVcd::flush_all() { - for (vluint32_t ent = 0; ent< s_vcdVecp.size(); ent++) { - VerilatedVcd* vcdp = s_vcdVecp[ent]; + for (vluint32_t ent = 0; ent< singleton().s_vcdVecp.size(); ent++) { + VerilatedVcd* vcdp = singleton().s_vcdVecp[ent]; vcdp->flush(); } } diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index 201fe9d1b..377a3e899 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -101,8 +101,12 @@ private: std::vector m_callbacks; ///< Routines to perform dumping typedef std::map NameMap; NameMap* m_namemapp; ///< List of names for the header + typedef std::vector VcdVec; - static VcdVec s_vcdVecp; ///< List of all created traces + struct Singleton { + VcdVec s_vcdVecp; ///< List of all created traces + }; + static Singleton& singleton() { static Singleton s; return s; } void bufferResize(vluint64_t minsize); void bufferFlush();