From f3e7ee0393a9ce0a4ebdc9732f169cdc8ce6dfaf Mon Sep 17 00:00:00 2001 From: tchernobog Date: Sun, 17 Sep 2006 17:05:43 +0000 Subject: [PATCH] - Fix bunch of nasty bugs into ConcreteHistory git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1241 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/concrete_history.cc | 30 +++++++++++++++++++++++------- src/backend/schedulable.cc | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/backend/concrete_history.cc b/src/backend/concrete_history.cc index dc3b398..87df971 100644 --- a/src/backend/concrete_history.cc +++ b/src/backend/concrete_history.cc @@ -397,7 +397,11 @@ ConcreteHistory::add_thread(const Glib::ustring& name, time_t arrival_time, prio_t base_priority) { - DynamicProcess& parent_process = down_cast(parent); + ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes(); + Process* p = deep_find(processes, parent); + if(!p) throw std::runtime_error(_("History::add_thread() : Parent process not part of this History")); + + DynamicProcess& parent_process = down_cast(*p); 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); @@ -428,14 +432,19 @@ DynamicRequest& ConcreteHistory::add_request(Thread& owner, time_t instant) { - DynamicThread& dyn_owner = down_cast(owner); + ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes(); + + Process* p = deep_find(processes, owner.get_process()); + if(!p) throw std::runtime_error(_("History::add_request() : Parent process not part of this History")); + Thread* t = deep_find(p->get_threads(), owner); + if(!t) throw std::runtime_error(_("History::add_request() : Parent thread not part of this History")); + + DynamicThread& dyn_owner = down_cast(*t); StaticThread& owner_core = dyn_owner.get_core(); StaticRequest* core = new StaticRequest(&owner_core, instant); DynamicRequest* req = new DynamicRequest(core, &dyn_owner); - dyn_owner.get_requests().push_back(req); - reset(); return *req; @@ -458,13 +467,20 @@ ConcreteHistory::add_subrequest(Request& request, resource_key_t resource_key, time_t duration) { - DynamicRequest& dyn_request = down_cast(request); + ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes(); + + Process* p = deep_find(processes, request.get_thread().get_process()); + if(!p) throw std::runtime_error(_("History::add_subrequest() : Parent process not part of this History")); + Thread* t = deep_find(p->get_threads(), request.get_thread()); + if(!t) throw std::runtime_error(_("History::add_subrequest() : Parent thread not part of this History")); + Request* r = deep_find(t->get_requests(), request); + if(!r) throw std::runtime_error(_("History::add_subrequest() : Parent request not part of this History")); + + DynamicRequest& dyn_request = down_cast(*r); StaticSubRequest* core = new StaticSubRequest(resource_key, duration); DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request); - dyn_request.get_subrequests().push_back(subreq); - reset(); return *subreq; diff --git a/src/backend/schedulable.cc b/src/backend/schedulable.cc index 02c5849..54c1d1c 100644 --- a/src/backend/schedulable.cc +++ b/src/backend/schedulable.cc @@ -20,6 +20,8 @@ #include +#include + using namespace sgpem; Schedulable::~Schedulable()