summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-01-12 16:16:56 -0800
committerGabe Black <gabeblack@google.com>2018-01-16 10:17:23 +0000
commit694672093ece3253c984d8809f64440022a82978 (patch)
tree0e9d98868ce45c6392e6d70f2e8aa19beba3bf8d
parentb8b13206c8d45cdcc16157d137845706bae915dd (diff)
downloadgem5-694672093ece3253c984d8809f64440022a82978.tar.xz
sim: Simplify registerThreadContext a little bit.
The code in this function was a little convoluted. This change attempts to simplify it a little bit to make it easier to read. Change-Id: I1ae557b9fede47fa89a9ea550bd0af8ad242449f Reviewed-on: https://gem5-review.googlesource.com/7421 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
-rw-r--r--src/sim/system.cc26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/sim/system.cc b/src/sim/system.cc
index e720db07a..2f047f227 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -241,23 +241,19 @@ bool System::breakpoint()
ContextID
System::registerThreadContext(ThreadContext *tc, ContextID assigned)
{
- int id;
- if (assigned == InvalidContextID) {
- for (id = 0; id < threadContexts.size(); id++) {
- if (!threadContexts[id])
- break;
- }
-
- if (threadContexts.size() <= id)
- threadContexts.resize(id + 1);
- } else {
- if (threadContexts.size() <= assigned)
- threadContexts.resize(assigned + 1);
- id = assigned;
+ int id = assigned;
+ if (id == InvalidContextID) {
+ // Find an unused context ID for this thread.
+ id = 0;
+ while (id < threadContexts.size() && threadContexts[id])
+ id++;
}
- if (threadContexts[id])
- fatal("Cannot have two CPUs with the same id (%d)\n", id);
+ if (threadContexts.size() <= id)
+ threadContexts.resize(id + 1);
+
+ fatal_if(threadContexts[id],
+ "Cannot have two CPUs with the same id (%d)\n", id);
threadContexts[id] = tc;
_numContexts++;