- Written DynamicProcess::get_state()

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@670 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-06-28 15:16:50 +00:00
parent 628010656e
commit a79b4a57d7
1 changed files with 40 additions and 3 deletions

View File

@ -51,9 +51,46 @@ DynamicProcess::get_threads()
Schedulable::state Schedulable::state
DynamicProcess::get_state() const DynamicProcess::get_state() const
{ {
// //TODO complicated code here! leave me some time to figure typedef vector<DynamicThread*>::const_iterator ThreadIt;
// // out what I need to do inside this method
return DynamicSchedulable::get_state(); assert(_dynamic_threads.size() > 0);
state result = _dynamic_threads[0]->get_state();
bool no_hole = false;
for(ThreadIt it = _dynamic_threads.begin(); it != _dynamic_threads.end(); ++it)
{
// This is the logic behind the code:
// If there is at least one running or ready thread, the result is
// the same. If not, it may be either blocked, future or terminated.
// This is guessed from the state of the first thread.
// We have three cases:
// - in case the first thread is blocked, this will be the result.
// - in case the first thread is terminated, a blocked thread will
// override the result and make the process blocked too.
// - in case the first thread is future, a blocked or terminated thread
// will override the result. If this isn't the case, also the absence of at least
// one future thread starting at instant 0 will make the result equal to terminated.
// TODO Is this OK? Must be tested...
if((*it)->get_state() == state_running || (*it)->get_state() == state_ready)
return (*it)->get_state();
else if((*it)->get_state() == state_blocked)
result = state_blocked;
else if(result == state_future)
{
if((*it)->get_state() == state_terminated)
result = state_terminated;
// NOTE this is not necessary, an else will equally work, but this is more clear...
else if((*it)->get_state() == state_future)
no_hole = no_hole || (*it)->get_arrival_time() == 0;
}
}
if(result == state_future && no_hole == false)
result = state_terminated;
return result;
} }
void void