diff options
author | Andreas Hansson <andreas.hansson@arm.com> | 2017-02-19 05:30:31 -0500 |
---|---|---|
committer | Andreas Hansson <andreas.hansson@arm.com> | 2017-02-19 05:30:31 -0500 |
commit | 184c6d7ebd7faa0869f294526a54a239a216b7c8 (patch) | |
tree | 136ca9e844392f986649f571c43393ef77a687ca /src/sim | |
parent | 912b20d02a4ec12b076e675ff150e3f1e89febaa (diff) | |
download | gem5-184c6d7ebd7faa0869f294526a54a239a216b7c8.tar.xz |
sim: Ensure draining is deterministic
The traversal of drainable objects could potentially be
non-deterministic when using an unordered set containing object
pointers. To ensure that the iteration is deterministic, we switch to
a vector. Note that the lookup and traversal of the drainable objects
is not performance critical, so the change has no negative consequences.
Diffstat (limited to 'src/sim')
-rw-r--r-- | src/sim/drain.cc | 11 | ||||
-rw-r--r-- | src/sim/drain.hh | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/sim/drain.cc b/src/sim/drain.cc index 085f781dc..bb8abd735 100644 --- a/src/sim/drain.cc +++ b/src/sim/drain.cc @@ -39,6 +39,8 @@ #include "sim/drain.hh" +#include <algorithm> + #include "base/misc.hh" #include "base/trace.hh" #include "debug/Drain.hh" @@ -126,6 +128,7 @@ DrainManager::preCheckpointRestore() void DrainManager::signalDrainDone() { + assert(_count > 0); if (--_count == 0) { DPRINTF(Drain, "All %u objects drained..\n", drainableCount()); exitSimLoop("Finished drain", 0); @@ -137,14 +140,18 @@ void DrainManager::registerDrainable(Drainable *obj) { std::lock_guard<std::mutex> lock(globalLock); - _allDrainable.insert(obj); + assert(std::find(_allDrainable.begin(), _allDrainable.end(), obj) == + _allDrainable.end()); + _allDrainable.push_back(obj); } void DrainManager::unregisterDrainable(Drainable *obj) { std::lock_guard<std::mutex> lock(globalLock); - _allDrainable.erase(obj); + auto o = std::find(_allDrainable.begin(), _allDrainable.end(), obj); + assert(o != _allDrainable.end()); + _allDrainable.erase(o); } size_t diff --git a/src/sim/drain.hh b/src/sim/drain.hh index b3145e7ed..663946616 100644 --- a/src/sim/drain.hh +++ b/src/sim/drain.hh @@ -42,7 +42,7 @@ #include <atomic> #include <mutex> -#include <unordered_set> +#include <vector> class Drainable; @@ -162,7 +162,7 @@ class DrainManager mutable std::mutex globalLock; /** Set of all drainable objects */ - std::unordered_set<Drainable *> _allDrainable; + std::vector<Drainable *> _allDrainable; /** * Number of objects still draining. This is flagged atomic since |