From 6af3a7df1f42fe2ff1cb32ed5d373ce39691281f Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Mon, 5 Feb 2018 17:08:43 +0000 Subject: sim: Remove _numContexts member in System class A System object has a _numContexts member variable which represent the number of ThreadContext registered in the System. Since this has to match the size of the ThreadContext vector, this patch removes the manually cached size. This was usually used as a for-loop index, whereas we want to enforce the use of range-based loops whenever possible. Change-Id: I1ba317c0393bcc9c1aeebbb1fc22d7b2bc2cf90c Signed-off-by: Giacomo Travaglini Reviewed-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/8062 Reviewed-by: Gabe Black Maintainer: Brandon Potter --- src/sim/system.cc | 17 +++++++++-------- src/sim/system.hh | 7 +------ 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'src/sim') diff --git a/src/sim/system.cc b/src/sim/system.cc index ed01e0e64..38eed1c2a 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -47,6 +47,8 @@ #include "sim/system.hh" +#include + #include "arch/remote_gdb.hh" #include "arch/utility.hh" #include "base/loader/object_file.hh" @@ -87,7 +89,6 @@ int System::numSystemsRunning = 0; System::System(Params *p) : MemObject(p), _systemPort("system_port", this), - _numContexts(0), multiThread(p->multi_thread), pagePtr(0), init_param(p->init_param), @@ -256,7 +257,6 @@ System::registerThreadContext(ThreadContext *tc, ContextID assigned) "Cannot have two CPUs with the same id (%d)\n", id); threadContexts[id] = tc; - _numContexts++; #if THE_ISA != NULL_ISA int port = getRemoteGDBPort(); @@ -287,12 +287,13 @@ System::registerThreadContext(ThreadContext *tc, ContextID assigned) int System::numRunningContexts() { - int running = 0; - for (int i = 0; i < _numContexts; ++i) { - if (threadContexts[i]->status() != ThreadContext::Halted) - ++running; - } - return running; + return std::count_if( + threadContexts.cbegin(), + threadContexts.cend(), + [] (ThreadContext* tc) { + return tc->status() != ThreadContext::Halted; + } + ); } void diff --git a/src/sim/system.hh b/src/sim/system.hh index 5b0c17872..a72f2a762 100644 --- a/src/sim/system.hh +++ b/src/sim/system.hh @@ -196,7 +196,6 @@ class System : public MemObject #endif std::vector threadContexts; - int _numContexts; const bool multiThread; ThreadContext *getThreadContext(ContextID tid) @@ -204,11 +203,7 @@ class System : public MemObject return threadContexts[tid]; } - int numContexts() - { - assert(_numContexts == (int)threadContexts.size()); - return _numContexts; - } + unsigned numContexts() const { return threadContexts.size(); } /** Return number of running (non-halted) thread contexts in * system. These threads could be Active or Suspended. */ -- cgit v1.2.3