- Me again: still more simplified code for DynamicProcess::get_state().
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@673 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
d7259b8963
commit
7aecc910ba
|
@ -70,67 +70,50 @@ DynamicProcess::get_state() const
|
|||
// running. If not, it may be either blocked, ready, future or terminated.
|
||||
|
||||
// We have these cases (a state takes precedence over some other one):
|
||||
// (a) result starts as future
|
||||
// (b) if a thread is running, return immediately state_running
|
||||
// (c) if a thread is ready, puts unconditionally result as state_ready,
|
||||
// (a) if a thread is running, return immediately state_running
|
||||
// (b) if a thread is ready, puts unconditionally result as state_ready,
|
||||
// and continue iterating (to see if there's a running thread)
|
||||
// (d) if a thread is blocked, and result is not state_ready, result
|
||||
// (c) if a thread is blocked, and result is not state_ready, result
|
||||
// becomes state_blocked, and continue iterating (to see if there are
|
||||
// ready or running threads)
|
||||
// (e) if a thread is future, and result is not state_ready or
|
||||
// (d) if a thread is future, and result is not state_ready or
|
||||
// state_blocked, put result as state_future, and remember
|
||||
// when the next thread will start (e1) (see at the end of this
|
||||
// method for the rationale (e2)). Then continue iterating.
|
||||
// (f) else (if all threads are state_terminated) put result as
|
||||
// when the next thread will start (d1) (see at the end of this
|
||||
// method for the rationale (d2)). Then continue iterating.
|
||||
// (e) else (if all threads are state_terminated) put result as
|
||||
// state_terminated.
|
||||
|
||||
// TODO Is this OK? Must be tested...
|
||||
|
||||
// (b)
|
||||
if(thread_state == state_running)
|
||||
switch(thread_state) {
|
||||
case state_running: // (a)
|
||||
return state_running;
|
||||
|
||||
// (c)
|
||||
if(thread_state == state_ready)
|
||||
{
|
||||
result = state_ready;
|
||||
continue;
|
||||
}
|
||||
|
||||
// (d)
|
||||
if(thread_state == state_blocked)
|
||||
{
|
||||
result = state_blocked;
|
||||
continue;
|
||||
}
|
||||
|
||||
// (e)
|
||||
if(thread_state == state_future)
|
||||
{
|
||||
result = state_future;
|
||||
int thread_starts_at = (*it)->get_arrival_time();
|
||||
|
||||
// (e1)
|
||||
if(next_thread_starts_at == uninitialized)
|
||||
next_thread_starts_at = thread_starts_at;
|
||||
else
|
||||
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
|
||||
continue;
|
||||
}
|
||||
|
||||
// (f)
|
||||
if(thread_state == state_terminated)
|
||||
case state_ready: // (b)
|
||||
result = state_ready;
|
||||
continue;
|
||||
case state_blocked: // (c)
|
||||
result = state_blocked;
|
||||
continue;
|
||||
case state_future: // (d)
|
||||
result = state_future;
|
||||
int thread_starts_at = (*it)->get_arrival_time();
|
||||
if(next_thread_starts_at == uninitialized) // (d1)
|
||||
next_thread_starts_at = thread_starts_at;
|
||||
else
|
||||
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
|
||||
continue;
|
||||
default: // (e)
|
||||
result = state_terminated;
|
||||
}
|
||||
|
||||
} //~ "for" iterating over threads
|
||||
|
||||
|
||||
// Now check if a "hole" happens: if result == state_future, but the next
|
||||
// thread to start, e.g. the one with the least arrival_time, has
|
||||
// start time greater than the current process elapsed time, then
|
||||
// pass from state_future to state_terminated:
|
||||
|
||||
// (e2)
|
||||
// (d2)
|
||||
int elapsed_time = get_total_cpu_time() - get_remaining_time();
|
||||
if(result == state_future && next_thread_starts_at > elapsed_time )
|
||||
result = state_terminated;
|
||||
|
|
Loading…
Reference in New Issue