Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/7421

Change subject: sim: Simplify registerThreadContext a little bit.
......................................................................

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
---
M src/sim/system.cc
1 file changed, 11 insertions(+), 15 deletions(-)



diff --git a/src/sim/system.cc b/src/sim/system.cc
index e720db0..2f047f2 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -241,23 +241,19 @@
 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++;

--
To view, visit https://gem5-review.googlesource.com/7421
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ae557b9fede47fa89a9ea550bd0af8ad242449f
Gerrit-Change-Number: 7421
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to