diff --git a/src/backend/concrete_simulation.cc b/src/backend/concrete_simulation.cc index 4af1801..462afb1 100644 --- a/src/backend/concrete_simulation.cc +++ b/src/backend/concrete_simulation.cc @@ -56,7 +56,7 @@ ConcreteSimulation::get_mode() const } void -ConcreteSimulation::jump_to(History::position p) +ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, NullPolicyException, MalformedPolicyException) { switch (_state) { diff --git a/src/backend/concrete_simulation.hh b/src/backend/concrete_simulation.hh index c05ea33..2c0a210 100644 --- a/src/backend/concrete_simulation.hh +++ b/src/backend/concrete_simulation.hh @@ -44,7 +44,7 @@ namespace sgpem void pause(); - void jump_to(History::position p); + void jump_to(History::position p) throw(UserInterruptException, NullPolicyException, MalformedPolicyException); void stop(); diff --git a/src/backend/resource_policy.hh b/src/backend/resource_policy.hh index ebc7864..9e436b0 100644 --- a/src/backend/resource_policy.hh +++ b/src/backend/resource_policy.hh @@ -28,6 +28,8 @@ #include "policy_parameters.hh" #include "user_interrupt_exception.hh" +#include "environment.hh" +#include "sub_request.hh" namespace sgpem { @@ -56,7 +58,7 @@ namespace sgpem Because it's a pure virtual method, must be re-implemented in concrete derived classes. */ - virtual void enforce() throw(UserInterruptException) = 0; + virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) throw(UserInterruptException) = 0; /** Gets a string description of the policy. diff --git a/src/backend/resource_policy_lifo.cc b/src/backend/resource_policy_lifo.cc index 6f09a00..d0efd0f 100644 --- a/src/backend/resource_policy_lifo.cc +++ b/src/backend/resource_policy_lifo.cc @@ -19,6 +19,8 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "resource_policy_lifo.hh" + + using namespace std; using namespace sgpem; @@ -39,10 +41,24 @@ ResourcePolicyLiFo::configure() } void -ResourcePolicyLiFo::enforce() +ResourcePolicyLiFo::enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) throw(UserInterruptException) { + typedef Environment::SubRequestQueue SubRequestQueue; printf("\nResourcePolicy 'LiFo' has been called."); + + // the last inserted request goes on the first free place. + SubRequestQueue old_queue(queue); + queue.clear(); + + typedef SubRequestQueue::iterator It; + for (It i = old_queue.begin(); i != old_queue.end(); i++) + { + // just rebuilds the queue by now. + queue.push_back(*i); + } + + printf("\nResourcePolicy 'LiFo' has terminated."); } Glib::ustring diff --git a/src/backend/resource_policy_lifo.hh b/src/backend/resource_policy_lifo.hh index 591ad97..e181bf4 100644 --- a/src/backend/resource_policy_lifo.hh +++ b/src/backend/resource_policy_lifo.hh @@ -27,6 +27,7 @@ #include "glibmm/ustring.h" #include "resource_policy.hh" + #include "policy_parameters.hh" #include "user_interrupt_exception.hh" @@ -57,7 +58,7 @@ namespace sgpem Because it's a pure virtual method, must be re-implemented in concrete derived classes. */ - virtual void enforce() throw(UserInterruptException); + virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) throw(UserInterruptException); /** Gets a string description of the policy. diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 7fa3ffb..fe0c374 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -176,7 +176,7 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme /// TODO: right here, right now we should call the resource policy to /// update the queue. Updates the state of the subrequest depending /// on the position in the queue, as explained before. - resource_policy.enforce(); + //resource_policy.enforce(environment, queue, cur_subr); // Get the number of places for the corresponding resource Resource& resource = *environment.get_resources().find(rkey)->second; diff --git a/src/backend/simulation.hh b/src/backend/simulation.hh index 7568ac2..fcc79ec 100644 --- a/src/backend/simulation.hh +++ b/src/backend/simulation.hh @@ -113,7 +113,7 @@ namespace sgpem Pauses the simulation and jumps to the specified instant */ - virtual void jump_to(History::position p) = 0; + virtual void jump_to(History::position p) throw(UserInterruptException, NullPolicyException, MalformedPolicyException) = 0; /** diff --git a/src/testsuite/scheduling-wizards/wizard-gap-blocked b/src/testsuite/scheduling-wizards/wizard-gap-blocked new file mode 100755 index 0000000..30f1bd8 --- /dev/null +++ b/src/testsuite/scheduling-wizards/wizard-gap-blocked @@ -0,0 +1,51 @@ +set cpu-policy 2 + +add resource +forchetta +1 + +add process +Pitagorici +0 +0 + +add thread 1 +Pitagora +5 +0 +0 +add request 1 1 +0 +add subrequest 1 1 1 +0 +5 + + +add process +Scuola di Mileto +2 +1 + +add thread 2 +Anassimene +4 +1 +0 + + +add thread 2 +Anassimandro +2 +0 +0 +add request 2 2 +0 +add subrequest 2 2 1 +0 +1 +add subrequest 2 2 1 +0 +2 + + +run diff --git a/src/testsuite/scheduling-wizards/wizard-gap-terminated b/src/testsuite/scheduling-wizards/wizard-gap-terminated new file mode 100755 index 0000000..4463513 --- /dev/null +++ b/src/testsuite/scheduling-wizards/wizard-gap-terminated @@ -0,0 +1,30 @@ +set cpu-policy 1 + + + + +add process +Rivoluzione +0 +1 + +add thread 1 +Copernico +3 +0 +0 + + +add thread 1 +Bruno +2 +3 +0 + +add thread 1 +Galilei +3 +6 +0 + +run diff --git a/src/testsuite/scheduling-wizards/wizard-resource-lifo b/src/testsuite/scheduling-wizards/wizard-resource-lifo new file mode 100755 index 0000000..e3a572c --- /dev/null +++ b/src/testsuite/scheduling-wizards/wizard-resource-lifo @@ -0,0 +1,64 @@ +set cpu-policy 2 + +configure-cpu-policy +0 +2 + +add resource +Telefono +1 + +add resource +Fax +1 + + + +add process +Ufficio Sinistri +0 +5 + +add thread 1 +Fantozzi +7 +0 +5 +add request 1 1 +0 +add subrequest 1 1 1 +0 +7 + +add thread 1 +Filini +3 +2 +4 +add request 1 2 +0 +add subrequest 1 2 1 +0 +3 +add subrequest 1 2 1 +1 +3 + + +add thread 1 +Signorina Silvani +4 +4 +3 +add request 1 3 +0 +add subrequest 1 3 1 +0 +2 +add subrequest 1 3 1 +1 +2 + + + +run