- removed Scheduler-initiated events

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@604 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-06-03 15:51:38 +00:00
parent 8062dd95da
commit da39407173
15 changed files with 21 additions and 55 deletions

View File

@ -36,13 +36,10 @@ class Policy:
# #
# Should be implemented with signature: # Should be implemented with signature:
# @code # @code
# def sort_queue(self, event, queue): # def sort_queue(self, queue):
# # function body # # function body
# @endcode # @endcode
# #
# @param event Enumeration value of type Scheduler::Event,
# needed by some policies to know the reason of
# the call
# @param queue The sgpem::SchedulableQueue to be sorted. # @param queue The sgpem::SchedulableQueue to be sorted.
# Only some methods of it are implemented, # Only some methods of it are implemented,
# notably get_item_at(position), # notably get_item_at(position),

View File

@ -19,9 +19,6 @@ class ScriptAdapter :
## @var The policy this ScriptAdapter will use for calls ## @var The policy this ScriptAdapter will use for calls
_policy = None _policy = None
## @var The event to pass to Policy.sort_queue() after the asynchronous call
_event = None
## @var Synchronized return value you can read from C++ ## @var Synchronized return value you can read from C++
# when a threaded function returns # when a threaded function returns
_ret_val = None _ret_val = None
@ -59,19 +56,16 @@ class ScriptAdapter :
# singleton, via SWIG # singleton, via SWIG
# #
# @param self The caller object # @param self The caller object
# @param event The event to pass to sort_queue def async_sort_queue(self):
def async_sort_queue(self, event):
self._event = event
self._g_mutex.lock(ScriptAdapter._wrap_sort_queue, self) self._g_mutex.lock(ScriptAdapter._wrap_sort_queue, self)
def _wrap_sort_queue(self): def _wrap_sort_queue(self):
thread.start_new_thread(ScriptAdapter._wrap_sort_queue_callback, thread.start_new_thread(ScriptAdapter._wrap_sort_queue_callback, (self,))
(self,self._event))
def _wrap_sort_queue_callback(self, event): def _wrap_sort_queue_callback(self):
# here we retrieve and pass the ready queue # here we retrieve and pass the ready queue
queue = sgpem.Scheduler.get_instance().get_ready_queue() queue = sgpem.Scheduler.get_instance().get_ready_queue()
self._policy.sort_queue(event, queue) self._policy.sort_queue(queue)
self._g_mutex.unlock() self._g_mutex.unlock()

View File

@ -35,7 +35,7 @@ class fcfs(Policy) :
def get_time_slice(self): def get_time_slice(self):
return -2 return -2
def sort_queue(self, event, queue): def sort_queue(self, queue):
cmpf = lambda a, b: \ cmpf = lambda a, b: \
a.get_schedulable().get_arrival_time() < \ a.get_schedulable().get_arrival_time() < \
b.get_schedulable().get_arrival_time() b.get_schedulable().get_arrival_time()

View File

@ -35,7 +35,7 @@ class sjf(Policy) :
def get_time_slice(self): def get_time_slice(self):
return -1 return -1
def sort_queue(self, event, queue): def sort_queue(self, queue):
cmpf = lambda a, b: \ cmpf = lambda a, b: \
a.get_cpu_time_left() < \ a.get_cpu_time_left() < \
b.get_cpu_time_left() b.get_cpu_time_left()

View File

@ -98,18 +98,16 @@ PythonPolicy::configure() throw(UserInterruptException)
void void
PythonPolicy::sort_queue(Scheduler::event event) const throw(UserInterruptException) PythonPolicy::sort_queue() const throw(UserInterruptException)
{ {
PyObject* pEvent = PyInt_FromLong(event);
PyObject* pMethodName = PyString_FromString("async_sort_queue"); PyObject* pMethodName = PyString_FromString("async_sort_queue");
PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, pEvent, NULL); PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, NULL, NULL);
// Do minimal debugging // Do minimal debugging
if(!retval) PyErr_Print(); if(!retval) PyErr_Print();
else Py_DECREF(retval); else Py_DECREF(retval);
Py_DECREF(pMethodName); Py_DECREF(pMethodName);
Py_DECREF(pEvent);
wait_unlock(); wait_unlock();
} }

View File

@ -56,7 +56,7 @@ namespace sgpem
/** /**
Calls the method \c async_sort_queue Calls the method \c async_sort_queue
*/ */
void sort_queue(Scheduler::event) const throw(UserInterruptException); void sort_queue() const throw(UserInterruptException);
/** /**
\returns A textual description of this policy. \returns A textual description of this policy.

View File

@ -16,5 +16,5 @@ class python_loader_configure(Policy) :
def get_time_slice(self): def get_time_slice(self):
return -1 return -1
def sort_queue(self, event, queue): def sort_queue(self, queue):
pass pass

View File

@ -17,5 +17,5 @@ class python_loader_get_time_slice(Policy) :
pass pass
return -1 return -1
def sort_queue(self, event, queue): def sort_queue(self, queue):
pass pass

View File

@ -17,5 +17,5 @@ class python_loader_is_preemptive(Policy) :
def get_time_slice(self): def get_time_slice(self):
return -1 return -1
def sort_queue(self, event, queue): def sort_queue(self, queue):
pass pass

View File

@ -14,7 +14,7 @@ class python_loader_sort_queue(Policy) :
def get_time_slice(self): def get_time_slice(self):
return -1 return -1
def sort_queue(self, event, queue): def sort_queue(self, queue):
print "[II] Entering willingly an endless loop." print "[II] Entering willingly an endless loop."
while True: while True:
pass pass

View File

@ -106,7 +106,7 @@ main(int argc, char** argv) {
{ {
SchedulableQueue sl; SchedulableQueue sl;
polman.test_init("python_loader_sort_queue"); polman.test_init("python_loader_sort_queue");
polman.get_policy().sort_queue(Scheduler::event_schedulable_arrival); polman.get_policy().sort_queue();
} }
catch(UserInterruptException e) catch(UserInterruptException e)
{ {

View File

@ -60,9 +60,8 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented Because it's a pure virtual method, must be re-implemented
in concrete derived classes. in concrete derived classes.
\param event Call reason. Needed only by some scheduling policies.
*/ */
virtual void sort_queue(Scheduler::event event) const throw(UserInterruptException) = 0; virtual void sort_queue() const throw(UserInterruptException) = 0;
/** /**
Gets the unique identifier (id) of this Policy. Gets the unique identifier (id) of this Policy.
@ -81,9 +80,6 @@ namespace sgpem
/** /**
Tell if this policy is preemptible. Tell if this policy is preemptible.
If true, for the \ref Scheduler::SCHEDULABLE_ARRIVAL event, the
ready queue will contain also the running \ref Schedulable;
else the running Schedulable will not be in the queue.
Because it's a pure virtual method, must be re-implemented Because it's a pure virtual method, must be re-implemented
in concrete derived classes. in concrete derived classes.

View File

@ -126,7 +126,7 @@ Scheduler::step_forward() throw(UserInterruptException)
initial->get_item_at(i)->set_state(SchedulableStatus::state_ready); initial->get_item_at(i)->set_state(SchedulableStatus::state_ready);
// Sort the queue // Sort the queue
policy.sort_queue(event_schedulable_arrival); policy.sort_queue();
//restore the old running schedulable //restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr) if (policy.is_pre_emptive() == false && running_ptr)
@ -153,14 +153,14 @@ Scheduler::step_forward() throw(UserInterruptException)
running_ptr = NULL; running_ptr = NULL;
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!! //IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
policy.sort_queue(event_schedulable_termination); policy.sort_queue();
} }
//***************** //*****************
// Check for time slice // Check for time slice
//***************** //*****************
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
policy.sort_queue(event_end_time_slice); policy.sort_queue();
//****************** //******************
// Create the final list of schedulable // Create the final list of schedulable

View File

@ -55,25 +55,6 @@ namespace sgpem
class SG_DLLEXPORT Scheduler class SG_DLLEXPORT Scheduler
{ {
public: public:
/** The events that may cause the need for updating the scheduling queue
and/or the running process.
*/
enum event
{
/**
The arrival of a newly-created process.
*/
event_schedulable_arrival,
/**
The termination of the executing process.
*/
event_schedulable_termination,
/**
The end of the executing process' time quantum.
*/
event_end_time_slice
};
/** \brief Returns the unique instance of this class, conforming to the Singleton pattern. /** \brief Returns the unique instance of this class, conforming to the Singleton pattern.
* *
* If Scheduler isn't initialized, creates it. Should be called at least once before * If Scheduler isn't initialized, creates it. Should be called at least once before

View File

@ -80,7 +80,7 @@ namespace sgpem
{ {
} }
virtual void sort_queue(Scheduler::event event) const throw(UserInterruptException) virtual void sort_queue() const throw(UserInterruptException)
{ // here a lot of fun, exactly O(n^2) fun! { // here a lot of fun, exactly O(n^2) fun!
SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time()); SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time());
for (int i = 0; i < sl.size(); i++) for (int i = 0; i < sl.size(); i++)