diff --git a/src/backend/concrete_history.cc b/src/backend/concrete_history.cc index 0348663..1b491a1 100644 --- a/src/backend/concrete_history.cc +++ b/src/backend/concrete_history.cc @@ -146,8 +146,6 @@ ConcreteHistory::remove(resource_key_t resource_key) if (found == resources.end()) return; - reset(false); - delete found->second; resources.erase(found); @@ -195,7 +193,7 @@ ConcreteHistory::remove(resource_key_t resource_key) // for example. Or hangovers. Or being read poetry by a Vogon. // Although the above construct really rates between the first tens. - notify_change(); + reset(); } @@ -207,7 +205,7 @@ ConcreteHistory::remove(Process& process) ConcreteEnvironment::Processes& processes = initial.get_processes(); bool found = deep_remove(processes, process); if (found) - reset(true); + reset(); } @@ -229,7 +227,7 @@ ConcreteHistory::remove(Thread& thread) bool removed = deep_remove(dynamic_found.get_dynamic_threads(), dyn_thr); if (removed) - reset(true); + reset(); } @@ -255,7 +253,7 @@ ConcreteHistory::remove(Request& request) bool removed = deep_remove(thr_ref->get_dynamic_requests(), dyn_req); if (removed) - reset(true); + reset(); } @@ -288,18 +286,16 @@ ConcreteHistory::remove(SubRequest& subrequest) bool removed = deep_remove(req_ref->get_dynamic_subrequests(), dyn_sub); if (removed) - reset(true); + reset(); } void ConcreteHistory::clear() { - reset(false); - assert(_snapshots.size() == 1); delete _snapshots.front(); _snapshots.front() = new ConcreteEnvironment(); - notify_change(); + reset(); } @@ -309,8 +305,6 @@ ConcreteHistory::add_resource(const Glib::ustring& name, size_t places, size_t availability) { - reset(false); - typedef ConcreteEnvironment::Resources Resources; typedef ConcreteEnvironment::SubRequestQueue SubRequestQueue; // And preemptable and availability?? FIXME! @@ -332,8 +326,7 @@ ConcreteHistory::add_resource(const Glib::ustring& name, SubRequestQueue emptysrq; _snapshots.front()->get_subrequest_queues().insert(pair(index, emptysrq)); - - notify_change(); + reset(); return *temp; } @@ -353,7 +346,7 @@ ConcreteHistory::edit_resource(Resource& resource, core.set_name(name); core.set_places(places); - reset(true); + reset(); } @@ -362,15 +355,14 @@ ConcreteHistory::add_process(const Glib::ustring& name, time_t arrival_time, prio_t base_priority) { - reset(false); - StaticProcess* core = new StaticProcess(name, arrival_time, base_priority); DynamicProcess* proc = new DynamicProcess(core); ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes(); processes.push_back(proc); - notify_change(); + reset(); + return *proc; } @@ -387,7 +379,7 @@ ConcreteHistory::edit_process(Process& process, core.set_arrival_time(arrival_time); core.set_priority(base_priority); - reset(true); + reset(); } @@ -399,14 +391,13 @@ ConcreteHistory::add_thread(const Glib::ustring& name, time_t arrival_time, prio_t base_priority) { - reset(false); - DynamicProcess& parent_process = down_cast(parent); StaticProcess& parent_core = parent_process.get_core(); StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority); DynamicThread* thread = new DynamicThread(core, &parent_process); - notify_change(); + reset(); + return *thread; } @@ -424,15 +415,13 @@ ConcreteHistory::edit_thread(Thread& thread, core.set_arrival_time(arrival_time); core.set_priority(base_priority); - reset(true); + reset(); } DynamicRequest& ConcreteHistory::add_request(Thread& owner, time_t instant) { - reset(false); - DynamicThread& dyn_owner = down_cast(owner); StaticThread& owner_core = dyn_owner.get_core(); @@ -441,7 +430,8 @@ ConcreteHistory::add_request(Thread& owner, dyn_owner.get_requests().push_back(req); - notify_change(); + reset(); + return *req; } @@ -453,7 +443,7 @@ ConcreteHistory::edit_request(Request& request, StaticRequest& core = req->get_core(); core.set_instant(instant); - reset(true); + reset(); } @@ -462,8 +452,6 @@ ConcreteHistory::add_subrequest(Request& request, resource_key_t resource_key, time_t duration) { - reset(false); - DynamicRequest& dyn_request = down_cast(request); StaticSubRequest* core = new StaticSubRequest(resource_key, duration); @@ -471,7 +459,8 @@ ConcreteHistory::add_subrequest(Request& request, dyn_request.get_subrequests().push_back(subreq); - notify_change(); + reset(); + return *subreq; } @@ -485,14 +474,7 @@ ConcreteHistory::edit_subrequest(SubRequest& subrequest, core.set_resource_key(resource_key); core.set_length(duration); - reset(true); -} - - -void -ConcreteHistory::reset() -{ - reset(true); + reset(); } @@ -509,9 +491,15 @@ ConcreteHistory::set_front(position p) notify_change(); } + void -ConcreteHistory::reset(bool notify) +ConcreteHistory::reset() { +#ifndef NDEBUG + static unsigned int n = 0; + std::cerr << "ConcreteHistory::reset() called for the " << ++n << "-th time." << std::endl; +#endif + assert(_snapshots.size() > 0); Snapshots::iterator it = _snapshots.begin(); it++; // Skip first environment that we saved @@ -521,8 +509,7 @@ ConcreteHistory::reset(bool notify) _front = 0; _sealed = false; - if (notify) - notify_change(); + notify_change(); } diff --git a/src/backend/concrete_history.hh b/src/backend/concrete_history.hh index 7a7b680..bfbd392 100644 --- a/src/backend/concrete_history.hh +++ b/src/backend/concrete_history.hh @@ -118,7 +118,6 @@ namespace sgpem bool seal(); void reset(); // Implements a virtual method - void reset(bool notify); // Only available in this class protected: typedef std::vector Snapshots; diff --git a/src/backend/cpu_policies_gatekeeper.cc b/src/backend/cpu_policies_gatekeeper.cc index 828ce1d..3111e8a 100644 --- a/src/backend/cpu_policies_gatekeeper.cc +++ b/src/backend/cpu_policies_gatekeeper.cc @@ -124,7 +124,7 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) thro policy->activate(); _active_policies[history] = policy; // the content of history (if any) is not vaild any more. - down_cast(history)->reset(true); + down_cast(history)->reset(); } catch(const CPUPolicyException& e) { diff --git a/src/backend/resource_policies_gatekeeper.cc b/src/backend/resource_policies_gatekeeper.cc index f22f8fc..1f35d8a 100644 --- a/src/backend/resource_policies_gatekeeper.cc +++ b/src/backend/resource_policies_gatekeeper.cc @@ -98,7 +98,7 @@ ResourcePoliciesGatekeeper::activate_policy(History *history, ResourcePolicy* po _active_policies[history] = policy; // the content of history (if any) is not vaild any more. - down_cast(history)->reset(true); + down_cast(history)->reset(); } ResourcePoliciesGatekeeper::ResourcePoliciesGatekeeper() diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 2db8123..5d59398 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -19,13 +19,14 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +/* // DISCLAIMER FOR THE RAMPANT CODER: \\ // ----------------------------------------------------\\ // ``If you touch this code, your ass is grass, \\ // and I'm the lawnmover.'' \\ // -- David Cutler \\ // ----------------------------------------------------\\ - +*/ #include "concrete_environment.hh" #include "concrete_history.hh"