From ec7c6a7c81e0cd0bca58b3c4d9350dfe2b75f8df Mon Sep 17 00:00:00 2001 From: elvez Date: Mon, 19 Jun 2006 22:37:27 +0000 Subject: [PATCH] - Added Thread class - Synchronized DynamicSchedulable and DynamicProcess with changes in design git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@637 3ecf2c5c-341e-0410-92b4-d18e462d057c --- Makefile.am | 2 ++ src/backend/dynamic_process.cc | 49 ++++++++++++++++++++++-------- src/backend/dynamic_process.hh | 12 +++++--- src/backend/dynamic_schedulable.cc | 41 ++++++++----------------- src/backend/dynamic_schedulable.hh | 19 ++++++------ src/backend/process.hh | 9 ++---- src/backend/thread.cc | 28 +++++++++++++++++ src/backend/thread.hh | 49 ++++++++++++++++++++++++++++++ 8 files changed, 148 insertions(+), 61 deletions(-) create mode 100644 src/backend/thread.cc create mode 100644 src/backend/thread.hh diff --git a/Makefile.am b/Makefile.am index 2250401..2664e03 100644 --- a/Makefile.am +++ b/Makefile.am @@ -160,6 +160,7 @@ src_backend_libbackend_la_SOURCES = \ src/backend/static_schedulable.cc \ src/backend/static_thread.cc \ src/backend/string_utils.cc \ + src/backend/thread.cc \ src/backend/user_interrupt_exception.cc pkginclude_HEADERS = \ @@ -183,6 +184,7 @@ pkginclude_HEADERS = \ src/backend/static_schedulable.hh \ src/backend/static_thread.hh \ src/backend/string_utils.hh \ + src/backend/thread.hh \ src/backend/user_interrupt_exception.hh # ############################################################ diff --git a/src/backend/dynamic_process.cc b/src/backend/dynamic_process.cc index a0e6a36..c73e89a 100644 --- a/src/backend/dynamic_process.cc +++ b/src/backend/dynamic_process.cc @@ -21,11 +21,13 @@ #include "dynamic_process.hh" #include "static_process.hh" +#include + using namespace sgpem; using std::vector; -DynamicProcess::DynamicProcess(StaticProcess& core) : - DynamicSchedulable(core) +DynamicProcess::DynamicProcess(StaticProcess* core) : + DynamicSchedulable(*core) { } @@ -34,6 +36,8 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) : { typedef vector::iterator ThreadIt; + _static_process = other._static_process; + const vector& other_threads = other._dynamic_threads; // FIXME uncomment when DynamicThread is complete @@ -41,26 +45,47 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) : // _dynamic_threads.push_back(new DynamicThread(*(*it))); } -std::vector DynamicProcess::get_threads() +std::vector +DynamicProcess::get_threads() { //FIXME uncomment when DynamicThread is complete //return vector(_dynamic_threads.begin(), _dynamic_threads.end()); return vector(); } -//FIXME already implemented in DynamicSchedulable -//state get_state() const -//{ +Schedulable::state +DynamicProcess::get_state() const +{ // //TODO complicated code here! leave me some time to figure // // out what I need to do inside this method -//} - -std::vector DynamicProcess::get_dynamic_threads() -{ - return _dynamic_threads; + return DynamicSchedulable::get_state(); } -void DynamicProcess::serialize(SerializeVisitor& translator) +void +DynamicProcess::remove_thread(Thread* thread) +{ + assert(thread != NULL); + + //FIXME uncomment me once DynamicThread is complete + //vector::iterator it; + + //it = std::find(_dynamic_threads.begin(), _dynamic_threads.end(), thread); + + //FIXME Do I need to deallocate the associated memory? + //if(it != _dynamic_threads.end()) + // _dynamic_threads.erase(it); +} + +void +DynamicProcess::add_thread(DynamicThread* thread) +{ + assert(thread != NULL); + + _dynamic_threads.push_back(thread); +} + +void +DynamicProcess::serialize(SerializeVisitor& translator) const { //FIXME write this code. I'm predictable, I know } diff --git a/src/backend/dynamic_process.hh b/src/backend/dynamic_process.hh index e61a61a..648ae85 100644 --- a/src/backend/dynamic_process.hh +++ b/src/backend/dynamic_process.hh @@ -27,6 +27,7 @@ #include #include "process.hh" +#include "../templates/smartp.hh" #include "dynamic_schedulable.hh" namespace sgpem @@ -39,20 +40,21 @@ namespace sgpem class SG_DLLEXPORT DynamicProcess : public DynamicSchedulable, public Process { public: - DynamicProcess(StaticProcess& core); + DynamicProcess(StaticProcess* core); DynamicProcess(const DynamicProcess &other); std::vector get_threads(); - //FIXME already implemented in DynamicSchedulable - //state get_state() const; + state get_state() const; - std::vector get_dynamic_threads(); + void remove_thread(Thread* thread); + void add_thread(DynamicThread* thread); - void serialize(SerializeVisitor& translator); + void serialize(SerializeVisitor& translator) const; private: std::vector _dynamic_threads; + memory::smart_ptr _static_process; }; } diff --git a/src/backend/dynamic_schedulable.cc b/src/backend/dynamic_schedulable.cc index 103ce9a..35eaecf 100644 --- a/src/backend/dynamic_schedulable.cc +++ b/src/backend/dynamic_schedulable.cc @@ -25,7 +25,7 @@ using namespace std; DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) : _time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1), - _last_release(-1), _current_priority(obj.get_priority()), _last(-1), + _last_release(-1), _priority_push(0), _last(-1), _my_state(state_future) { } @@ -42,36 +42,18 @@ DynamicSchedulable::get_name() const return _ref->get_name(); } -void -DynamicSchedulable::set_name(const Glib::ustring& new_name) -{ - _ref->set_name(new_name); -} - unsigned int DynamicSchedulable::get_arrival_time() const { return _ref->get_arrival_time(); } -void -DynamicSchedulable::set_arrival_time(unsigned int new_time) -{ - _ref->set_arrival_time(new_time); -} - int DynamicSchedulable::get_base_priority() const { return _ref->get_priority(); } -void -DynamicSchedulable::set_base_priority(int new_priority) -{ - _ref->set_priority(new_priority); -} - unsigned int DynamicSchedulable::get_total_cpu_time() const { @@ -79,15 +61,22 @@ DynamicSchedulable::get_total_cpu_time() const } int -DynamicSchedulable::get_current_priority() const +DynamicSchedulable::get_priority_push() const { - return _current_priority; + return _priority_push; } void -DynamicSchedulable::set_current_priority(int new_priority) +DynamicSchedulable::set_priority_push(int new_value) { - _current_priority = new_priority; + _priority_push = new_value; +} + +int +DynamicSchedulable::get_current_priority() const +{ + //TODO is this correct? + return get_base_priority() + get_priority_push(); } unsigned int @@ -126,12 +115,6 @@ DynamicSchedulable::set_last_release(int instant) _last_release = instant; } -void -DynamicSchedulable::serialize(SerializeVisitor& translator) const -{ - //TODO write me as part of the serialization infrastructure -} - int DynamicSchedulable::get_cpu_time_left() const { diff --git a/src/backend/dynamic_schedulable.hh b/src/backend/dynamic_schedulable.hh index ea5daaf..961c8fe 100644 --- a/src/backend/dynamic_schedulable.hh +++ b/src/backend/dynamic_schedulable.hh @@ -60,17 +60,15 @@ namespace sgpem unsigned int get_arrival_time() const; - void set_arrival_time(unsigned int new_time); - int get_base_priority() const; - void set_base_priority(int new_priority); - unsigned int get_total_cpu_time() const; - int get_current_priority() const; + int get_priority_push() const; - void set_current_priority(int new_priority); + void set_priority_push(int new_value = 0); + + int get_current_priority() const; unsigned int get_remaining_time() const; @@ -84,8 +82,7 @@ namespace sgpem void set_last_release(int instant); - void serialize(SerializeVisitor& translator) const; - + /* FIXME all following methods are deprecated, drop them @@ -112,6 +109,10 @@ namespace sgpem */ void set_state(state s); + void serialize(SerializeVisitor& translator) const + { + } + /** \brief Returns a pointer to the schedulable object * * This function returns a pointer to the actual schedable object @@ -126,7 +127,7 @@ namespace sgpem StaticSchedulable* _ref; int _last_acquisition; int _last_release; - int _current_priority; + int _priority_push; //FIXME deprecated stuff used by deprecated methods int _last; diff --git a/src/backend/process.hh b/src/backend/process.hh index 6142d0a..4c50361 100644 --- a/src/backend/process.hh +++ b/src/backend/process.hh @@ -22,7 +22,6 @@ #define PROCESS_HH 1 #include "config.h" -#include "gettext.h" #include "glibmm/ustring.h" #include @@ -32,17 +31,15 @@ namespace sgpem { class Process; class Thread; + class SerializeVisitor; class SG_DLLEXPORT Process : public virtual Schedulable { public: virtual ~Process(); + virtual std::vector get_threads() = 0; - virtual void add_thread(const Glib::ustring& name, - unsigned int cpu_time, - unsigned int arrival_time = 0, - int base_priority = 0) = 0; - virtual void remove_thread(Thread *thread) = 0; + virtual void serialize(SerializeVisitor& translator) const = 0; }; } diff --git a/src/backend/thread.cc b/src/backend/thread.cc new file mode 100644 index 0000000..fa86ea2 --- /dev/null +++ b/src/backend/thread.cc @@ -0,0 +1,28 @@ +// src/backend/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 "thread.hh" + +using namespace sgpem; + +Thread::~Thread() +{ +} + diff --git a/src/backend/thread.hh b/src/backend/thread.hh new file mode 100644 index 0000000..2178e13 --- /dev/null +++ b/src/backend/thread.hh @@ -0,0 +1,49 @@ +// src/backend/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 THREAD_HH +#define THREAD_HH 1 + +#include "config.h" +#include + +#include "schedulable.hh" + +namespace sgpem +{ + class Thread; + class Request; + class Process; + class SerializeVisitor; + + class SG_DLLEXPORT Thread : public virtual Schedulable + { + public: + virtual ~Thread(); + + virtual Process& get_process() = 0; + virtual std::vector get_requests() = 0; + virtual void serialize(SerializeVisitor& translator) const= 0; + }; + +} + +#endif +