Internals: Use singleton in place of global

This commit is contained in:
Wilson Snyder 2017-09-23 07:44:52 -04:00
parent c2e8062f84
commit 3f14e649b5
2 changed files with 10 additions and 11 deletions

View File

@ -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();
}
}

View File

@ -101,8 +101,12 @@ private:
std::vector<VerilatedVcdCallInfo*> m_callbacks; ///< Routines to perform dumping
typedef std::map<std::string,std::string> NameMap;
NameMap* m_namemapp; ///< List of names for the header
typedef std::vector<VerilatedVcd*> 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();