Internals: Split Mutex class used in verilated code and verilator (#4048)

This commit is contained in:
Kamil Rakoczy
2023-04-11 07:23:24 -04:00
committed by GitHub
parent 0307d59c1f
commit b6dcec2710
18 changed files with 249 additions and 74 deletions
+6 -6
View File
@@ -40,7 +40,7 @@ template <typename T>
class V3ConfigWildcardResolver final {
using Map = std::map<const std::string, T>;
mutable VerilatedMutex m_mutex; // protects members
mutable V3Mutex m_mutex; // protects members
Map m_mapWildcard VL_GUARDED_BY(m_mutex); // Wildcard strings to entities
Map m_mapResolved VL_GUARDED_BY(m_mutex); // Resolved strings to converged entities
public:
@@ -50,21 +50,21 @@ public:
/// Update into maps from other
void update(const V3ConfigWildcardResolver& other) VL_MT_SAFE_EXCLUDES(m_mutex)
VL_EXCLUDES(other.m_mutex) {
VerilatedLockGuard lock{m_mutex};
VerilatedLockGuard otherLock{other.m_mutex};
V3LockGuard lock{m_mutex};
V3LockGuard otherLock{other.m_mutex};
for (const auto& itr : other.m_mapResolved) m_mapResolved[itr.first].update(itr.second);
for (const auto& itr : other.m_mapWildcard) m_mapWildcard[itr.first].update(itr.second);
}
// Access and create a (wildcard) entity
T& at(const string& name) VL_MT_SAFE_EXCLUDES(m_mutex) {
VerilatedLockGuard lock{m_mutex};
V3LockGuard lock{m_mutex};
// Don't store into wildcards if the name is not a wildcard string
return m_mapWildcard[name];
}
// Access an entity and resolve wildcards that match it
T* resolve(const string& name) VL_MT_SAFE_EXCLUDES(m_mutex) {
VerilatedLockGuard lock{m_mutex};
V3LockGuard lock{m_mutex};
// Lookup if it was resolved before, typically not
auto it = m_mapResolved.find(name);
if (VL_UNLIKELY(it != m_mapResolved.end())) return &it->second;
@@ -85,7 +85,7 @@ public:
}
// Flush on update
void flush() VL_MT_SAFE_EXCLUDES(m_mutex) {
VerilatedLockGuard lock{m_mutex};
V3LockGuard lock{m_mutex};
m_mapResolved.clear();
}
};