Workaround missing guard (partial #2333).

This commit is contained in:
Wilson Snyder 2020-05-19 08:31:52 -04:00
parent 7834028842
commit c64c81b7a3
1 changed files with 4 additions and 3 deletions

View File

@ -483,21 +483,21 @@ public: // But only for verilated*.cpp
} }
static void fdFlush(IData fdi) VL_MT_SAFE { static void fdFlush(IData fdi) VL_MT_SAFE {
FILE* fp[30]; FILE* fp[30];
VerilatedLockGuard lock(s_s.m_fdMutex);
const int n = fdToFp(fdi, fp, 30); const int n = fdToFp(fdi, fp, 30);
VerilatedLockGuard lock(s_s.m_fdMutex);
for (int i = 0; i < n; i++) fflush(fp[i]); for (int i = 0; i < n; i++) fflush(fp[i]);
} }
static IData fdSeek(IData fdi, IData offset, IData origin) VL_MT_SAFE { static IData fdSeek(IData fdi, IData offset, IData origin) VL_MT_SAFE {
FILE* fp; FILE* fp;
VerilatedLockGuard lock(s_s.m_fdMutex);
const int n = fdToFp(fdi, &fp); const int n = fdToFp(fdi, &fp);
VerilatedLockGuard lock(s_s.m_fdMutex);
if (VL_UNLIKELY(!fp || (n != 1))) return 0; if (VL_UNLIKELY(!fp || (n != 1))) return 0;
return static_cast<IData>(fseek(fp, static_cast<long>(offset), static_cast<int>(origin))); return static_cast<IData>(fseek(fp, static_cast<long>(offset), static_cast<int>(origin)));
} }
static IData fdTell(IData fdi) VL_MT_SAFE { static IData fdTell(IData fdi) VL_MT_SAFE {
FILE* fp; FILE* fp;
VerilatedLockGuard lock(s_s.m_fdMutex);
const int n = fdToFp(fdi, &fp); const int n = fdToFp(fdi, &fp);
VerilatedLockGuard lock(s_s.m_fdMutex);
if (VL_UNLIKELY(!fp || (n != 1))) return 0; if (VL_UNLIKELY(!fp || (n != 1))) return 0;
return static_cast<IData>(ftell(fp)); return static_cast<IData>(ftell(fp));
} }
@ -524,6 +524,7 @@ public: // But only for verilated*.cpp
} }
static inline int fdToFp(IData fdi, FILE** fp, std::size_t max = 1) VL_MT_SAFE { static inline int fdToFp(IData fdi, FILE** fp, std::size_t max = 1) VL_MT_SAFE {
if (VL_UNLIKELY(!fp || (max == 0))) return 0; if (VL_UNLIKELY(!fp || (max == 0))) return 0;
VerilatedLockGuard lock(s_s.m_fdMutex);
int out = 0; int out = 0;
if ((fdi & (1 << 31)) != 0) { if ((fdi & (1 << 31)) != 0) {
// Non-MCD case // Non-MCD case