- Fix compilation of libbackend.so

- Erased Scheduler::step_forward(): reimplementing from
scratch


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@701 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-03 20:55:19 +00:00
parent e2fc34f16b
commit 94f7c1d127
11 changed files with 45 additions and 167 deletions

View File

@ -169,7 +169,6 @@ src_backend_libbackend_la_SOURCES = \
src/backend/resource.cc \
src/backend/schedulable.cc \
src/backend/scheduler.cc \
src/backend/slice.cc \
src/backend/static_process.cc \
src/backend/static_request.cc \
src/backend/static_resource.cc \

View File

@ -360,9 +360,8 @@ ConcreteHistory::add_subrequest(Request& request,
reset(false);
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
StaticRequest& request_core = dyn_request.get_core();
StaticSubRequest* core = new StaticSubRequest(&request_core, resource_key, duration, places);
StaticSubRequest* core = new StaticSubRequest(resource_key, duration, places);
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
dyn_request.get_subrequests().push_back(subreq);

View File

@ -56,157 +56,37 @@ Scheduler::get_ready_queue()
void
Scheduler::reset_status()
{
_ready_queue.clear();
History::get_instance().truncate_at(0);
// restore the policy
// DEPRECATED (?)
}
/* void
Scheduler::set_policy(Policy* p)
{
_policy_manager.set_policy(p);
}*/
Policy&
Scheduler::get_policy()
{
//return _policy_manager.get_policy();
return *PoliciesGatekeeper::get_instance().get_current_policy(&History::get_instance());
// FIXME : fixme.
// return *PoliciesGatekeeper::get_instance().get_current_policy(&History::get_instance());
}
void
Scheduler::step_forward() throw(UserInterruptException)
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
{
try
{
Policy& policy = get_policy();
History& h = History::get_instance();
//******************
//check for arrivals and prepare the queue
//******************
smart_ptr<ReadyQueue> initial = h.get_simulation_status_at(h.get_current_time());
if (!initial)
{
cout << _("\nNo initial state inserted!!\n");
return;
}
_ready_queue.clear();
//adds running schedulable
smart_ptr<DynamicSchedulable> running_ptr = h.get_scheduled_at(h.get_current_time());
if (running_ptr)
_ready_queue.add_at_top(*running_ptr);
//adds the READY ones
for(uint rea = 0; rea < initial->size(); rea++)
if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready)
_ready_queue.add_at_bottom(*initial->get_item_at(rea));
//adds each new ready schedulable and sorts the queue
for(uint i = 0; i < initial->size(); i++)
if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
{
//cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.remove(0);
//adds the NEW one
_ready_queue.add_at_bottom(*initial->get_item_at(i));
_ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_ready);
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
// Sort the queue
policy.sort_queue();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.add_at_top(*running_ptr);
}
//****************
// Check for termination
//****************
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
{
//there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED
for(uint i = 0; i < _ready_queue.size(); i++)
if (*_ready_queue.get_item_at(i) == *running_ptr)
{
_ready_queue.add_at_bottom(*_ready_queue.get_item_at(i));
_ready_queue.remove(i);
_ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_terminated);
break;
}
//cout << "\nTERMINATO!!";
running_ptr = NULL;
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
policy.sort_queue();
}
//*****************
// Check for time slice
//*****************
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
policy.sort_queue();
//******************
// Create the final list of schedulable
//******************
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready
|| _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running))
{
//the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
_ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running);
_ready_queue.get_item_at(0)->give_cpu_time(1);
}
//all the others are ready
for (uint i = 1; i < _ready_queue.size(); i++)
if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running)
_ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready);
//append blocked, future, and terminated schedulables
for (uint i = 0; i < initial->size(); i++)
if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
_ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n";
/* for (uint i = 0; i < _ready_queue.size(); i++)
cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name()
<<"_" << _ready_queue.get_item_at(i)->get_state();
*/
h.enqueue_slice(_ready_queue);
}
catch( UserInterruptException e )
{
_policy_manager.init();
throw;
//TODO Do we need to perform some cleanup operation here?
// Do we need to update something?
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
// maybe it's that??? oh, damn.
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
// Tell:
// Going up unwinding the stack, tell:
// - the user that the policy sucks
// - SimulationController that everything stopped
throw;
}
}

View File

@ -33,6 +33,7 @@ namespace sgpem
#include <iostream>
#include "history.hh"
#include "policy.hh"
#include "ready_queue.hh"
#include "user_interrupt_exception.hh"
@ -43,6 +44,7 @@ namespace sgpem
{
class Scheduler;
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
Class Scheduler manages the schedulable entities which are ready to run,
@ -74,7 +76,7 @@ namespace sgpem
at the simulation instant next to the current one, and extends the History by
one instant with it.
*/
void step_forward() throw(UserInterruptException);
void step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException);
/**
Sets the policy that will be used to generate the simulation at the next instant.
\param policy the policy that will be used to generate the simulation at the next instant.

View File

@ -41,7 +41,7 @@ StaticProcess::get_arrival_time() const
unsigned int
StaticProcess::get_total_cpu_time() const
{
tyepdef std::vector<Thread*>::iterator ThreadIterator;
typedef std::vector<StaticThread*>::const_iterator ThreadIterator;
unsigned int result = 0;
for(ThreadIterator it = _threads.begin(); it != _threads.end(); it++)

View File

@ -32,6 +32,7 @@
namespace sgpem
{
class StaticProcess;
class StaticThread;
/** \brief Represents a program in execution.

View File

@ -21,6 +21,8 @@
#ifndef STATIC_REQUEST_HH
#define STATIC_REQUEST_HH 1
#include "static_thread.hh"
#include "config.h"
#include "glibmm/ustring.h"
@ -28,12 +30,12 @@ namespace sgpem
{
class StaticRequest;
class SerializeVisitor;
class StaticThread;
class SG_DLLLOCAL StaticRequest
{
public:
StaticRequest(StaticThread* thread, unsigned int instant);
~StaticRequest();
unsigned int get_instant() const;
StaticThread& get_thread();

View File

@ -18,6 +18,7 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "static_request.hh"
#include "static_sub_request.hh"
#include <algorithm>
@ -26,37 +27,33 @@
using namespace sgpem;
StaticSubRequest::StaticSubRequest(StaticRequest* req,
resource_key_t resource_key,
StaticSubRequest::StaticSubRequest(resource_key_t resource_key,
unsigned int length,
unsigned int places) :
_static_request(req), _resource_key(resource_key),
_resource_key(resource_key),
_length(length), _places(places)
{
assert(req != NULL && resource != NULL);
req->get_subrequests().push_back(this);
//A static request doesn't keep track of its static subrequests
//at least for now.
//req->get_subrequests().push_back(this);
}
StaticSubRequest::~StaticSubRequest()
{
typedef std::vector<StaticSubRequest*> SubRequests;
SubRequests siblings& = _static_request.get_subrequests();
siblings.erase(find(siblings.begin(), siblings.end(), this));
// See comment in constructor.
// typedef std::vector<StaticSubRequest*> SubRequests;
// SubRequests siblings& = _static_request.get_subrequests();
// siblings.erase(find(siblings.begin(), siblings.end(), this));
}
SubRequest::get_resource_key
SubRequest::resource_key_t
StaticSubRequest::get_resource_key() const
{
return _resource_key;
}
StaticRequest&
StaticSubRequest::get_static_request()
{
return *_static_request;
}
unsigned int
StaticSubRequest::get_places() const
{
@ -68,4 +65,3 @@ StaticSubRequest::get_length() const
{
return _length;
}

View File

@ -36,17 +36,14 @@ namespace sgpem
public:
typedef SubRequest::resource_key_t resource_key_t;
StaticSubRequest(StaticRequest* req,
resource_key_t resource_key,
StaticSubRequest(resource_key_t resource_key,
unsigned int length,
unsigned int places = 1);
virtual ~StaticSubRequest();
~StaticSubRequest();
resource_key_t get_resource_key() const;
StaticRequest& get_request();
unsigned int get_places() const;
unsigned int get_length() const;
@ -55,7 +52,6 @@ namespace sgpem
StaticSubRequest(const StaticSubRequest&);
StaticSubRequest& operator=(const StaticSubRequest&);
StaticRequest* _static_request;
resource_key_t _resource_key;
unsigned int _length;
unsigned int _places;

View File

@ -44,8 +44,8 @@ StaticThread::StaticThread(const Glib::ustring& name,
StaticThread::~StaticThread()
{
typedef std::vector<StaticThread*> Threads;
Threads siblings& = _process.get_threads();
siblings.erase(find(siblings.begin(), siblings.end(), this);
Threads& siblings = _process->get_threads();
siblings.erase(find(siblings.begin(), siblings.end(), this));
}
@ -70,5 +70,5 @@ StaticThread::get_process()
std::vector<StaticRequest*>&
StaticThread::get_requests()
{
return _requests;
return _static_requests;
}

View File

@ -21,17 +21,20 @@
#ifndef STATIC_THREAD_HH
#define STATIC_THREAD_HH 1
#include "static_process.hh"
#include "static_schedulable.hh"
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
#include <vector>
#include "static_schedulable.hh"
#include <glibmm/ustring.h>
#include <vector>
namespace sgpem
{
class StaticThread;
class StaticProcess;
class StaticThread;
class StaticRequest;
class SG_DLLLOCAL StaticThread : public StaticSchedulable