- 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
This commit is contained in:
elvez 2006-06-19 22:37:27 +00:00
parent 30d070a420
commit ec7c6a7c81
8 changed files with 148 additions and 61 deletions

View File

@ -160,6 +160,7 @@ src_backend_libbackend_la_SOURCES = \
src/backend/static_schedulable.cc \ src/backend/static_schedulable.cc \
src/backend/static_thread.cc \ src/backend/static_thread.cc \
src/backend/string_utils.cc \ src/backend/string_utils.cc \
src/backend/thread.cc \
src/backend/user_interrupt_exception.cc src/backend/user_interrupt_exception.cc
pkginclude_HEADERS = \ pkginclude_HEADERS = \
@ -183,6 +184,7 @@ pkginclude_HEADERS = \
src/backend/static_schedulable.hh \ src/backend/static_schedulable.hh \
src/backend/static_thread.hh \ src/backend/static_thread.hh \
src/backend/string_utils.hh \ src/backend/string_utils.hh \
src/backend/thread.hh \
src/backend/user_interrupt_exception.hh src/backend/user_interrupt_exception.hh
# ############################################################ # ############################################################

View File

@ -21,11 +21,13 @@
#include "dynamic_process.hh" #include "dynamic_process.hh"
#include "static_process.hh" #include "static_process.hh"
#include <cassert>
using namespace sgpem; using namespace sgpem;
using std::vector; using std::vector;
DynamicProcess::DynamicProcess(StaticProcess& core) : DynamicProcess::DynamicProcess(StaticProcess* core) :
DynamicSchedulable(core) DynamicSchedulable(*core)
{ {
} }
@ -34,6 +36,8 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) :
{ {
typedef vector<DynamicThread*>::iterator ThreadIt; typedef vector<DynamicThread*>::iterator ThreadIt;
_static_process = other._static_process;
const vector<DynamicThread*>& other_threads = other._dynamic_threads; const vector<DynamicThread*>& other_threads = other._dynamic_threads;
// FIXME uncomment when DynamicThread is complete // FIXME uncomment when DynamicThread is complete
@ -41,26 +45,47 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) :
// _dynamic_threads.push_back(new DynamicThread(*(*it))); // _dynamic_threads.push_back(new DynamicThread(*(*it)));
} }
std::vector<Thread*> DynamicProcess::get_threads() std::vector<Thread*>
DynamicProcess::get_threads()
{ {
//FIXME uncomment when DynamicThread is complete //FIXME uncomment when DynamicThread is complete
//return vector<Thread*>(_dynamic_threads.begin(), _dynamic_threads.end()); //return vector<Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
return vector<Thread*>(); return vector<Thread*>();
} }
//FIXME already implemented in DynamicSchedulable Schedulable::state
//state get_state() const DynamicProcess::get_state() const
//{ {
// //TODO complicated code here! leave me some time to figure // //TODO complicated code here! leave me some time to figure
// // out what I need to do inside this method // // out what I need to do inside this method
//} return DynamicSchedulable::get_state();
std::vector<DynamicThread*> DynamicProcess::get_dynamic_threads()
{
return _dynamic_threads;
} }
void DynamicProcess::serialize(SerializeVisitor& translator) void
DynamicProcess::remove_thread(Thread* thread)
{
assert(thread != NULL);
//FIXME uncomment me once DynamicThread is complete
//vector<DynamicThread*>::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 //FIXME write this code. I'm predictable, I know
} }

View File

@ -27,6 +27,7 @@
#include <vector> #include <vector>
#include "process.hh" #include "process.hh"
#include "../templates/smartp.hh"
#include "dynamic_schedulable.hh" #include "dynamic_schedulable.hh"
namespace sgpem namespace sgpem
@ -39,20 +40,21 @@ namespace sgpem
class SG_DLLEXPORT DynamicProcess : public DynamicSchedulable, public Process class SG_DLLEXPORT DynamicProcess : public DynamicSchedulable, public Process
{ {
public: public:
DynamicProcess(StaticProcess& core); DynamicProcess(StaticProcess* core);
DynamicProcess(const DynamicProcess &other); DynamicProcess(const DynamicProcess &other);
std::vector<Thread*> get_threads(); std::vector<Thread*> get_threads();
//FIXME already implemented in DynamicSchedulable state get_state() const;
//state get_state() const;
std::vector<DynamicThread*> get_dynamic_threads(); void remove_thread(Thread* thread);
void add_thread(DynamicThread* thread);
void serialize(SerializeVisitor& translator); void serialize(SerializeVisitor& translator) const;
private: private:
std::vector<DynamicThread*> _dynamic_threads; std::vector<DynamicThread*> _dynamic_threads;
memory::smart_ptr<StaticProcess*> _static_process;
}; };
} }

View File

@ -25,7 +25,7 @@ using namespace std;
DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) : DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) :
_time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1), _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) _my_state(state_future)
{ {
} }
@ -42,36 +42,18 @@ DynamicSchedulable::get_name() const
return _ref->get_name(); return _ref->get_name();
} }
void
DynamicSchedulable::set_name(const Glib::ustring& new_name)
{
_ref->set_name(new_name);
}
unsigned int unsigned int
DynamicSchedulable::get_arrival_time() const DynamicSchedulable::get_arrival_time() const
{ {
return _ref->get_arrival_time(); return _ref->get_arrival_time();
} }
void
DynamicSchedulable::set_arrival_time(unsigned int new_time)
{
_ref->set_arrival_time(new_time);
}
int int
DynamicSchedulable::get_base_priority() const DynamicSchedulable::get_base_priority() const
{ {
return _ref->get_priority(); return _ref->get_priority();
} }
void
DynamicSchedulable::set_base_priority(int new_priority)
{
_ref->set_priority(new_priority);
}
unsigned int unsigned int
DynamicSchedulable::get_total_cpu_time() const DynamicSchedulable::get_total_cpu_time() const
{ {
@ -79,15 +61,22 @@ DynamicSchedulable::get_total_cpu_time() const
} }
int int
DynamicSchedulable::get_current_priority() const DynamicSchedulable::get_priority_push() const
{ {
return _current_priority; return _priority_push;
} }
void 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 unsigned int
@ -126,12 +115,6 @@ DynamicSchedulable::set_last_release(int instant)
_last_release = instant; _last_release = instant;
} }
void
DynamicSchedulable::serialize(SerializeVisitor& translator) const
{
//TODO write me as part of the serialization infrastructure
}
int int
DynamicSchedulable::get_cpu_time_left() const DynamicSchedulable::get_cpu_time_left() const
{ {

View File

@ -60,17 +60,15 @@ namespace sgpem
unsigned int get_arrival_time() const; unsigned int get_arrival_time() const;
void set_arrival_time(unsigned int new_time);
int get_base_priority() const; int get_base_priority() const;
void set_base_priority(int new_priority);
unsigned int get_total_cpu_time() const; 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; unsigned int get_remaining_time() const;
@ -84,8 +82,7 @@ namespace sgpem
void set_last_release(int instant); void set_last_release(int instant);
void serialize(SerializeVisitor& translator) const;
/* /*
FIXME FIXME
all following methods are deprecated, drop them all following methods are deprecated, drop them
@ -112,6 +109,10 @@ namespace sgpem
*/ */
void set_state(state s); void set_state(state s);
void serialize(SerializeVisitor& translator) const
{
}
/** \brief Returns a pointer to the schedulable object /** \brief Returns a pointer to the schedulable object
* *
* This function returns a pointer to the actual schedable object * This function returns a pointer to the actual schedable object
@ -126,7 +127,7 @@ namespace sgpem
StaticSchedulable* _ref; StaticSchedulable* _ref;
int _last_acquisition; int _last_acquisition;
int _last_release; int _last_release;
int _current_priority; int _priority_push;
//FIXME deprecated stuff used by deprecated methods //FIXME deprecated stuff used by deprecated methods
int _last; int _last;

View File

@ -22,7 +22,6 @@
#define PROCESS_HH 1 #define PROCESS_HH 1
#include "config.h" #include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h" #include "glibmm/ustring.h"
#include <vector> #include <vector>
@ -32,17 +31,15 @@ namespace sgpem
{ {
class Process; class Process;
class Thread; class Thread;
class SerializeVisitor;
class SG_DLLEXPORT Process : public virtual Schedulable class SG_DLLEXPORT Process : public virtual Schedulable
{ {
public: public:
virtual ~Process(); virtual ~Process();
virtual std::vector<Thread*> get_threads() = 0; virtual std::vector<Thread*> get_threads() = 0;
virtual void add_thread(const Glib::ustring& name, virtual void serialize(SerializeVisitor& translator) const = 0;
unsigned int cpu_time,
unsigned int arrival_time = 0,
int base_priority = 0) = 0;
virtual void remove_thread(Thread *thread) = 0;
}; };
} }

28
src/backend/thread.cc Normal file
View File

@ -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()
{
}

49
src/backend/thread.hh Normal file
View File

@ -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 <vector>
#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<Request*> get_requests() = 0;
virtual void serialize(SerializeVisitor& translator) const= 0;
};
}
#endif