From 905067d13f3abfcec61c5d2367312a10e3410ca3 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 2 Mar 2020 07:43:10 -0500 Subject: [PATCH] Fix $dumpvar multithreaded assert, broke last commit. --- include/verilated.h | 8 +++++++- include/verilated_fst_c.h | 3 +++ include/verilated_vcd_c.h | 4 ++++ src/V3EmitC.cpp | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/verilated.h b/include/verilated.h index 97becf9c3..90aa9ff53 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -201,13 +201,19 @@ public: /// Check that the current thread ID is the same as the construction thread ID void check() VL_MT_UNSAFE_ONE { if (VL_UNCOVERABLE(m_threadid != VL_THREAD_ID())) { - fatal_different(); // LCOV_EXCL_LINE + if (m_threadid == 0) { + m_threadid = VL_THREAD_ID(); + } else { + fatal_different(); // LCOV_EXCL_LINE + } } } + void changeThread() { m_threadid = 0; } // Allow intentional change-of-thread static void fatal_different() VL_MT_SAFE; #else // !VL_THREADED || !VL_DEBUG public: void check() {} + void changeThread() {} #endif }; diff --git a/include/verilated_fst_c.h b/include/verilated_fst_c.h index f6de80bb9..d9c0c6281 100644 --- a/include/verilated_fst_c.h +++ b/include/verilated_fst_c.h @@ -66,6 +66,7 @@ private: public: explicit VerilatedFst(void* fst=NULL); ~VerilatedFst() { if (m_fst == NULL) { fstWriterClose(m_fst); } } + void changeThread() { m_assertOne.changeThread(); } bool isOpen() const { return m_fst != NULL; } void open(const char* filename) VL_MT_UNSAFE; void flush() VL_MT_UNSAFE { fstWriterFlushContext(m_fst); } @@ -199,6 +200,8 @@ class VerilatedFstC { public: explicit VerilatedFstC(void* filep=NULL) : m_sptrace(filep) {} ~VerilatedFstC() { close(); } + /// Routines can only be called from one thread; allow next call from different thread + void changeThread() { spTrace()->changeThread(); } public: // ACCESSORS /// Is file open? diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index 690e3ec31..f0a5bcb9f 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -159,6 +159,8 @@ private: public: explicit VerilatedVcd(VerilatedVcdFile* filep = NULL); ~VerilatedVcd(); + /// Routines can only be called from one thread; allow next call from different thread + void changeThread() { m_assertOne.changeThread(); } // ACCESSORS /// Set size in megabytes after which new file should be created @@ -446,6 +448,8 @@ public: explicit VerilatedVcdC(VerilatedVcdFile* filep = NULL) : m_sptrace(filep) {} ~VerilatedVcdC() { close(); } + /// Routines can only be called from one thread; allow next call from different thread + void changeThread() { spTrace()->changeThread(); } public: // ACCESSORS /// Is file open? diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index e4efa36e9..529498764 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -3088,6 +3088,7 @@ class EmitCTrace : EmitCStmts { puts( "const char* cp = vl_dumpctl_filenamep();\n"); puts( "trace(__VlSymsp->__Vm_dumperp, 0, 0);\n"); puts( "__VlSymsp->__Vm_dumperp->open(vl_dumpctl_filenamep());\n"); + puts( "__VlSymsp->__Vm_dumperp->changeThread();\n"); puts( "}\n"); puts("}\n"); splitSizeInc(10);