- Implement a couple of helper methods into Dynamic(Sub)Request to

make life easier to Scheduler
- Go on implementing a bit more of Scheduler::step_forward()
- Remove "places" from SubRequest


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@778 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-18 15:52:55 +00:00
parent 53073295d5
commit 14b5b66b3c
13 changed files with 163 additions and 89 deletions

View file

@ -162,8 +162,10 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup
// increasing the time elapsed of the running thread + process
// should be done here as the first thing, instead than
// directly after selecting them
running_thread->decrease_remaining_time();
if(current.get_total_cpu_time() - current.get_elapsed_time() > 0)
running_thread->decrease_remaining_time();
assert(running_thread == NULL); // ... and one to bind them all.
running_thread = &current; // Even if we change its state to terminated
// 2. mark threads that used all their allotted time as terminated
if(current.get_total_cpu_time() - current.get_elapsed_time() == 0)
@ -179,41 +181,59 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup
}
// 4a. Look for exhausted requests for the running thread
if(running_thread != NULL) {
Requests& reqs = running_thread->get_dynamic_requests();
bool running_terminated = running_thread->get_state() == Schedulable::state_terminated;
if(running_thread != NULL)
{
Requests& reqs = running_thread->get_dynamic_requests();
bool running_terminated = running_thread->get_state() == Schedulable::state_terminated;
for(Requests::iterator it = reqs.begin(); it != reqs.end(); it++)
{
DynamicRequest& rq = **it;
if(rq.get_state() == Request::state_allocated)
/* decrease remaining time for request */;
// ASK MARCO : can we implement request::decrease_remaining_time() as
// a function that calls decrease_remaining_time() on all its subrequests,
// that in turn never go with a remaining time < 0?
// If the running thread terminated uncoditionally put them in exhausted state
if(running_terminated /* || rq.get_remaining_time() == 0 */ )
rq.set_state(Request::state_exhausted);
}
// FIXME we lack a way to tell and/or remember for how
// much a subrequest has been being fulfilled
// THIS MEANS this part is NOT complete
// We should check if a request has been fulfilled
// FIXME If a request was being fulfilled to the running thread,
// we should decrease the request remaining time here.
// This is why we kept a ref to the old running thread,
// even if it was terminated
} //~ if running_thread != NULL
for(Requests::iterator r_it = reqs.begin(); r_it != reqs.end(); r_it++)
{
DynamicRequest& rq = **r_it;
// If the running thread terminated uncoditionally put them in exhausted state
if(running_terminated)
{
SubRequests& subreqs = rq.get_dynamic_subrequests();
for(SubRequests::iterator s_it = subreqs.begin(); s_it != subreqs.end(); s_it++)
(*s_it)->set_state(Request::state_exhausted);
continue; // go to next request
}
if(rq.get_state() == Request::state_allocated)
{
/* decrease remaining time for each allocated subrequest */
SubRequests& subreqs = rq.get_dynamic_subrequests();
for(SubRequests::iterator s_it = subreqs.begin(); s_it != subreqs.end(); s_it++)
{
DynamicSubRequest& subr = **s_it;
if(subr.get_state() == Request::state_allocated)
subr.decrease_remaining_time();
if(subr.get_remaining_time() == 0)
{
subr.set_state(Request::state_exhausted);
// FIXME : if exhausted, it should be taken away from the queue of the
// requested resource
}
}
}
} //~ for(over requests)
// FIXME we lack a way to tell and/or remember for how
// much a subrequest has been being fulfilled
// THIS MEANS this part is NOT complete
// We should check if a request has been fulfilled
// FIXME If a request was being fulfilled to the running thread,
// we should decrease the request remaining time here.
// This is why we kept a ref to the old running thread,
// even if it was terminated
} //~ if running_thread != NULL
// ---------- FIXME ----------------
// What to do now if the simulation ended?