From e95d915e3a2d968903a8d093216b46d370073eab Mon Sep 17 00:00:00 2001 From: elvez Date: Wed, 21 Jun 2006 22:39:35 +0000 Subject: [PATCH] - Added DynamicThread class git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@649 3ecf2c5c-341e-0410-92b4-d18e462d057c --- Makefile.am | 2 + src/backend/dynamic_thread.cc | 109 ++++++++++++++++++++++++++++++++++ src/backend/dynamic_thread.hh | 71 ++++++++++++++++++++++ src/backend/static_thread.cc | 56 ++++++++++++----- src/backend/static_thread.hh | 19 +++--- 5 files changed, 234 insertions(+), 23 deletions(-) create mode 100644 src/backend/dynamic_thread.cc create mode 100644 src/backend/dynamic_thread.hh diff --git a/Makefile.am b/Makefile.am index 4af024e..d93e31b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -146,6 +146,7 @@ src_backend_libbackend_la_LDFLAGS = \ src_backend_libbackend_la_SOURCES = \ src/backend/dynamic_process.cc \ src/backend/dynamic_schedulable.cc \ + src/backend/dynamic_thread.cc \ src/backend/global_preferences.cc \ src/backend/history.cc \ src/backend/observed_subject.cc \ @@ -169,6 +170,7 @@ pkginclude_HEADERS += \ config.h \ src/backend/dynamic_process.hh \ src/backend/dynamic_schedulable.hh \ + src/backend/dynamic_thread.hh \ src/backend/global_preferences.hh \ src/backend/history.hh \ src/backend/observed_subject.hh \ diff --git a/src/backend/dynamic_thread.cc b/src/backend/dynamic_thread.cc new file mode 100644 index 0000000..77635f7 --- /dev/null +++ b/src/backend/dynamic_thread.cc @@ -0,0 +1,109 @@ +// src/backend/dynamic_thread.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "dynamic_thread.hh" +#include "static_thread.hh" + +#include + +using namespace sgpem; +using std::vector; + + +DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent) : + DynamicSchedulable(*core), _state(state_future), _parent(parent) +{ +} + +DynamicThread::DynamicThread(const DynamicThread &other) : + Schedulable(), DynamicSchedulable(other), Thread() +{ + typedef vector::iterator ReqIt; + + const vector& other_req = other._dynamic_requests; + + _state = other._state; + _parent = other._parent; + +// FIXME uncomment me once requests are ready +// for(ReqIt it = other_req.begin(); it != other_req.end(); ++it) +// _dynamic_requests.push_back(new DynamicRequest(*(*it))); +} + +DynamicProcess& +DynamicThread::get_process() +{ + return *_parent; +} + +Schedulable::state +DynamicThread::get_state() const +{ + return _state; +} + +Schedulable::state +DynamicThread::set_state(state new_state) +{ + state old_state = _state; + _state = new_state; + + return old_state; +} + +vector +DynamicThread::get_requests() +{ + // FIXME uncomment once requests are compelted + //return vector(_dynamic_requests.begin(), _dynamic_requests.end()); + return vector(); +} + +void +DynamicThread::remove_request(Request* request) +{ + assert(request != NULL); + + vector::iterator it; + + // FIXME uncomment once requests are compelted + //it = std::find(_dynamic_requests.begin(), _dynamic_requests.end(), request); + + //if(it != _dynamic_requests.end()) + //{ + // _dynamic_requests.erase(it); + // delete *it; + //} + +} + +void +DynamicThread::add_request(DynamicRequest* request) +{ + assert(request != NULL); + + _dynamic_requests.push_back(request); +} + +void +DynamicThread::serialize(SerializeVisitor& translator) const +{ + // TODO fill-in appropriate code +} diff --git a/src/backend/dynamic_thread.hh b/src/backend/dynamic_thread.hh new file mode 100644 index 0000000..44fbed0 --- /dev/null +++ b/src/backend/dynamic_thread.hh @@ -0,0 +1,71 @@ +// src/backend/dynamic_thread.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef DYNAMIC_THREAD_HH +#define DYNAMIC_THREAD_HH 1 + +#include "config.h" +#include "gettext.h" +#include "glibmm/ustring.h" +#include + +#include "thread.hh" +#include "dynamic_process.hh" +#include "../templates/smartp.hh" +#include "dynamic_schedulable.hh" + +namespace sgpem +{ + class DynamicThread; + class DynamicProcess; + class StaticThread; + class Request; + class DynamicRequest; + + class SG_DLLEXPORT DynamicThread : public DynamicSchedulable, public Thread + { + public: + DynamicThread(StaticThread* core, DynamicProcess* parent); + DynamicThread(const DynamicThread &other); + + DynamicProcess& get_process(); + + state get_state() const; + + state set_state(state new_state); + + std::vector get_requests(); + + void remove_request(Request* request); + + void add_request(DynamicRequest* request); + + void serialize(SerializeVisitor& translator) const; + + private: + state _state; + std::vector _dynamic_requests; + DynamicProcess* _parent; + }; + +} + +#endif + diff --git a/src/backend/static_thread.cc b/src/backend/static_thread.cc index 76d7281..f6c0b7b 100644 --- a/src/backend/static_thread.cc +++ b/src/backend/static_thread.cc @@ -19,7 +19,9 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "static_thread.hh" + using namespace sgpem; +using std::vector; StaticThread::StaticThread(const Glib::ustring& name, StaticProcess& process, @@ -31,24 +33,46 @@ StaticThread::StaticThread(const Glib::ustring& name, { } -// FIXME unmcomment when StaticSchedulable complies to the design -// unsigned int StaticThread::get_total_cpu_time() const -// { -// return _required_cpu_time; -// } -// -// unsigned int StaticThread::get_arrival_time() const -// { -// return _start_time_delta; -// } -// -// void StaticThread::set_arrival_time(unsigned int time) -// { -// _start_time_delta = time; -// } +unsigned int +StaticThread::get_total_cpu_time() const +{ + return _required_cpu_time; +} -StaticProcess& StaticThread::get_process() +unsigned int +StaticThread::get_arrival_time() const +{ + return _start_time_delta; +} + +StaticProcess& +StaticThread::get_process() { return *_process; } +void +StaticThread::remove_request(StaticRequest* request) +{ + assert(request != NULL); + + vector::iterator it; + + // FIXME uncomment once requests are compelted + //it = std::find(_static_requests.begin(), _static_requests.end(), request); + + //if(it != _static_requests.end()) + //{ + // _static_requests.erase(it); + // delete *it; + //} +} + +void +StaticThread::add_request(StaticRequest* request) +{ + assert(request != NULL); + + _static_requests.push_back(request); +} + diff --git a/src/backend/static_thread.hh b/src/backend/static_thread.hh index 30703c9..96ee77b 100644 --- a/src/backend/static_thread.hh +++ b/src/backend/static_thread.hh @@ -24,6 +24,7 @@ #include "config.h" #include "gettext.h" #include "glibmm/ustring.h" +#include #include "static_schedulable.hh" @@ -31,6 +32,7 @@ namespace sgpem { class StaticThread; class StaticProcess; + class StaticRequest; class SG_DLLEXPORT StaticThread : public StaticSchedulable { @@ -40,20 +42,23 @@ namespace sgpem unsigned int arrival_time = 0, int base_priority = 0); -// FIXME already implemented in StaticSchedulable where they should -// only be declared abstract... -// unsigned int get_total_cpu_time() const; -// -// unsigned int get_arrival_time() const; -// -// void set_arrival_time(unsigned int time); + unsigned int get_total_cpu_time() const; + + unsigned int get_arrival_time() const; StaticProcess& get_process(); + + void remove_request(StaticRequest* request); + + void add_request(StaticRequest* request); private: + StaticThread(const StaticThread&); + unsigned int _start_time_delta; unsigned int _required_cpu_time; StaticProcess* _process; + std::vector _static_requests; }; }