diff --git a/src/backend/dynamic_request.cc b/src/backend/dynamic_request.cc index ae926d6..4a7bd30 100644 --- a/src/backend/dynamic_request.cc +++ b/src/backend/dynamic_request.cc @@ -90,6 +90,15 @@ DynamicRequest::get_state() const } +Request::state +DynamicRequest::set_state(state new_state) +{ + state temp = _state; + _state = new_state; + return temp; +} + + void DynamicRequest::serialize(SerializeVisitor& translator) const { diff --git a/src/backend/dynamic_request.hh b/src/backend/dynamic_request.hh index 48fe48a..ac6381f 100644 --- a/src/backend/dynamic_request.hh +++ b/src/backend/dynamic_request.hh @@ -53,6 +53,7 @@ namespace sgpem unsigned int get_instant() const; state get_state() const; + state set_state(state new_state); void serialize(SerializeVisitor& translator) const; diff --git a/src/backend/dynamic_thread.cc b/src/backend/dynamic_thread.cc index ed57beb..63032bb 100644 --- a/src/backend/dynamic_thread.cc +++ b/src/backend/dynamic_thread.cc @@ -122,7 +122,10 @@ DynamicThread::get_elapsed_time() const void DynamicThread::decrease_remaining_time() { - _ran_for++; + // strict check for us to better debug scheduler + assert(_ran_for < get_total_cpu_time()); + if(_ran_for < get_total_cpu_time()) + _ran_for++; } int diff --git a/src/backend/dynamic_thread.hh b/src/backend/dynamic_thread.hh index 5aef98c..a9de32d 100644 --- a/src/backend/dynamic_thread.hh +++ b/src/backend/dynamic_thread.hh @@ -77,7 +77,7 @@ namespace sgpem std::vector _dynamic_requests; DynamicProcess* _parent; - int _ran_for; + unsigned int _ran_for; int _last_acquisition; int _last_release; }; diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 65c6523..793e801 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -68,7 +68,7 @@ static void prepare_ready_queue(ConcreteEnvironment& snapshot, it != all_threads.end(); it++) { if((*it)->get_state() == Schedulable::state_ready) - all_threads.push_back(*it); + queue.append(**it); } } @@ -178,21 +178,28 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup Schedulable::state_terminated)) == 0) simulation_ended = false; } - - - // ---------- FIXME ---------------- - // What to do now if the simulation ended? - - - // 4a. Requests for the running thread exhausted + // 4a. Look for exhausted requests for the running thread if(running_thread != NULL) { Requests& reqs = running_thread->get_dynamic_requests(); - if(running_thread->get_state() == Schedulable::state_terminated) + bool running_terminated = running_thread->get_state() == Schedulable::state_terminated; + + for(Requests::iterator it = reqs.begin(); it != reqs.end(); it++) { - // for(Requests::iterator it = reqs.begin(); - } - + 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 @@ -205,18 +212,23 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup // even if it was terminated - } + } //~ if running_thread != NULL + + + // ---------- FIXME ---------------- + // What to do now if the simulation ended? - // / - // / - // / - // (I'M HERE) < * * * * * * * * * * * - // \ - // \ - // \ - // - // (is it visible enough for you?) + /* / + * / + * / + * (I'M HERE) < * * * * * * * * * * * + * \ + * \ + * \ + * + * (is it visible enough for you?) + */ prepare_ready_queue(*new_snapshot, all_threads);