From c1665818b955c4730896315a580d0bbaffb3d95a Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Fri, 24 Apr 2020 03:09:26 +0100 Subject: [PATCH] Fix missing flush with threaded VCD tracing. (#2282) VerilatedVcdC::openNext() failed to flush the tracing thread before opening the next output file, which caused t_trace_cat.pl to fail with --vltmt on occasion. --- include/verilated_vcd_c.cpp | 12 ++++++------ include/verilated_vcd_c.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index c5ad6f7bb..9f5befff3 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -294,18 +294,17 @@ void VerilatedVcd::close() { // This function is on the flush() call path m_assertOne.check(); if (!isOpen()) return; - VerilatedTrace::close(); if (m_evcd) { printStr("$vcdclose "); printQuad(timeLastDump()); printStr(" $end\n"); } closePrev(); -} - -void VerilatedVcd::flush() { - VerilatedTrace::flush(); - bufferFlush(); + // closePrev() already called VerilatedTrace::flush() via + // bufferFlush(), and there were no opportunities to enqueue further + // buffers as this close() is running on the main thread the same as dump() + // so just shutting down the trace thread will suffice. + VerilatedTrace::close(); } void VerilatedVcd::printStr(const char* str) { @@ -343,6 +342,7 @@ void VerilatedVcd::bufferFlush() VL_MT_UNSAFE_ONE { // This is much faster than using buffered I/O m_assertOne.check(); if (VL_UNLIKELY(!isOpen())) return; + VerilatedTrace::flush(); char* wp = m_wrBufp; while (true) { ssize_t remaining = (m_writep - wp); diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index e9838c15b..0ee8084c8 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -149,7 +149,7 @@ public: /// Close the file void close() VL_MT_UNSAFE_ONE; /// Flush any remaining data to this file - void flush() VL_MT_UNSAFE_ONE; + void flush() VL_MT_UNSAFE_ONE { bufferFlush(); } /// Is file open? bool isOpen() const { return m_isOpen; }