- Mega-update. Take it while it's hot... but my brain's frying!

- Fixed all Dynamic and Static entities lacking proper destructors:
Dynamic entities need to delete Dynamic children, Static entities
need only to delete them from the list of their siblings
- Added methods to get Static "core" from Dynamic*.
- Now get_core() is a pure virtual function into DynamicSchedulable.
A quite nice solution(?), really, if I can say that myself... ;-)
- ConcreteHistory is half-implemented. It's the other half that 
worries me.
- TODO: finish off ConcreteHistory, and check that things get destroyed
properly (no leaks allowed, use valgrind).
- TODO: rework Simulation
- TODO: Scheduler rewrite
- *A side note*: this code is becoming a mess. I prefer references over
pointers, but someone other prefer pointers over references, and what
happens is that you've to continously pass from one to another when
invoking other methods... this is bad.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@694 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-02 22:20:03 +00:00
parent 787d24964b
commit 7d62f4b937
25 changed files with 564 additions and 321 deletions

View file

@ -22,3 +22,219 @@
#include "concrete_history.hh"
#include "static_process.hh"
#include "static_thread.hh"
#include "static_resource.hh"
#include "static_request.hh"
#include "static_sub_request.hh"
#include "smartp.tcc"
#include <algorithm>
#include <cassert>
#include <functional>
using namespace sgpem;
using namespace std;
using memory::smart_ptr;
ConcreteHistory::ConcreteHistory()
: History(), _snapshots()
{
_snapshots.push_back(new ConcreteEnvironment());
}
ConcreteHistory::~ConcreteHistory()
{
for_each(_snapshots.begin(), _snapshots.end(), ptr_fun(operator delete));
}
void
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
{
_snapshots.push_back(environment);
}
ConcreteHistory::size_t
ConcreteHistory::get_size()
{
return _snapshots.size();
}
const ConcreteEnvironment&
ConcreteHistory::get_last_environment() const
{
// Should always be true:
assert(_snapshots.size() > 0);
return *_snapshots.back();
}
const ConcreteEnvironment&
ConcreteHistory::get_environment_at(position index) const
throw(std::out_of_range)
{
return *_snapshots.at(index);
}
void
ConcreteHistory::remove(resource_key_t resource_key)
{
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Resources& resources = initial.get_resources();
ConcreteEnvironment::Resources::iterator found = resources.find(resource_key);
if(found == resources.end())
{
notify_change();
return; // not found, just return. Can we do this better (without a reset)?
}
reset(false);
// FIXME: I'm really tired, check that the next two lines do
// what they're meant to do!
delete found->second;
resources.erase(found);
#warning "write me!"
// FIXME write me : check for subrequests to remove
notify_change();
}
void
ConcreteHistory::remove(const Process& process)
{
reset(false);
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
ConcreteEnvironment::Processes::iterator found = find(processes.begin(), processes.end(), &process);
if(found == processes.end())
{
notify_change();
return; // not found, just return. Can we do this better (without a reset)?
}
// FIXME: I'm really tired, check that the next two lines do
// what they're meant to do!
delete *found;
processes.erase(found);
notify_change();
}
void
ConcreteHistory::remove(const Thread& thread)
{
#warning "write me!"
}
void
ConcreteHistory::remove(const Request& request)
{
#warning "write me!"
}
void
ConcreteHistory::remove(const SubRequest& subrequest)
{
#warning "write me!"
}
ConcreteHistory::ResourcePair&
ConcreteHistory::add_resource(const Glib::ustring& name,
bool preemptable,
size_t places,
size_t availability)
{
#warning "write me!"
}
DynamicProcess&
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();
}
DynamicThread&
ConcreteHistory::add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time,
prio_t base_priority)
{
reset(false);
// Holy cow! *THIS* is ugly!!!!
DynamicProcess& parent_process = dynamic_cast<DynamicProcess&>(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();
}
DynamicRequest&
ConcreteHistory::add_request(Thread& owner,
time_t instant)
{
#warning "write me!"
}
DynamicSubRequest&
ConcreteHistory::add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration,
size_t places)
{
#warning "write me!"
}
void
ConcreteHistory::reset(bool notify)
{
Snapshots::iterator it = _snapshots.begin();
ConcreteEnvironment* model = *it;
it++; // Skip first environment that we saved
for_each(it, _snapshots.end(), ptr_fun(operator delete));
_snapshots.clear();
_snapshots.push_back(new ConcreteEnvironment());
// FIXME write code to copy processes and threads and subrequests......
#warning "write me!"
delete model;
if(notify)
notify_change();
}