- Substitute the old SchedulableQueue with the new ReadyQueue
- Add interfaces for Process and Thread into the "sgpem.i" SWIG interface file, change DynamicSchedulable into Schedulable - Add dynamic_cast for the return value of ReadyQueue::get_item_at() into the pyloader "sgpem.i" SWIG interface, so that a Schedulable can be either recognized as a Thread or a Process - TODO: wrap STL exceptions in SWIG interface - Please note that code won't compile until the new History and Scheduler::step_forward() will be in place. This is a known issue. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@689 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
fa06e2f4f1
commit
759b90b017
24 changed files with 170 additions and 414 deletions
|
@ -40,7 +40,7 @@ class Policy:
|
|||
# # function body
|
||||
# @endcode
|
||||
#
|
||||
# @param queue The sgpem::SchedulableQueue to be sorted.
|
||||
# @param queue The sgpem::ReadyQueue to be sorted.
|
||||
# Only some methods of it are implemented,
|
||||
# notably get_item_at(position),
|
||||
# swap(positionA, positionB) and size().
|
||||
|
@ -113,7 +113,7 @@ class Policy:
|
|||
|
||||
|
||||
## @brief This function implements an in-place stable sort
|
||||
# using directly SchedulableQueue methods
|
||||
# using directly ReadyQueue methods
|
||||
#
|
||||
# The compare parameter should be a user defined binary
|
||||
# function returning either True or False, defined in one
|
||||
|
@ -137,7 +137,7 @@ class Policy:
|
|||
# @endcode
|
||||
#
|
||||
# @param self The object caller
|
||||
# @param queue The SchedulableQueue to be sorted in place
|
||||
# @param queue The ReadyQueue to be sorted in place
|
||||
# @param cmpf The binary function to use to compare elements
|
||||
# @returns None
|
||||
def sort(self, queue, cmpf):
|
||||
|
@ -167,7 +167,7 @@ class Policy:
|
|||
#
|
||||
# Feel the love.
|
||||
#
|
||||
# @param queue The SchedulableQueue to sort
|
||||
# @param queue The ReadyQueue to sort
|
||||
# @param a The partition starting element position in the queue
|
||||
# @param b The partition ending element position in the queue
|
||||
# @param cmpf The binary function to use for comparing two elements
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
%include "std_vector.i"
|
||||
|
||||
%module sgpem
|
||||
%{
|
||||
#include "policy.hh"
|
||||
#include "policy_parameters.hh"
|
||||
#include "static_schedulable.hh"
|
||||
#include "schedulable_queue.hh"
|
||||
#include "dynamic_schedulable.hh"
|
||||
#include "process.hh"
|
||||
#include "ready_queue.hh"
|
||||
#include "schedulable.hh"
|
||||
#include "scheduler.hh"
|
||||
#include "thread.hh"
|
||||
%}
|
||||
|
||||
/* NOTE : passing Unicode strings to C++ methods calling them
|
||||
|
@ -14,18 +17,22 @@
|
|||
* the sgpem user manual)
|
||||
*/
|
||||
|
||||
/** Due to the relatively new support for namespaces in SWIG,
|
||||
/* Due to the relatively new support for namespaces in SWIG,
|
||||
* make sure to include the full visibility signature when
|
||||
* returning / passing parameters from / to functions with
|
||||
* objects different to the one you're declaring.
|
||||
*/
|
||||
|
||||
/* FIXME : look up into Swig manual the management of
|
||||
* STL exceptions and write wrappers for them.
|
||||
*/
|
||||
|
||||
namespace std {
|
||||
class exception {
|
||||
public:
|
||||
virtual const char* what() const throw();
|
||||
private:
|
||||
exception();
|
||||
exception();
|
||||
};
|
||||
|
||||
class runtime_error : public std::exception {
|
||||
|
@ -36,6 +43,8 @@ namespace std {
|
|||
};
|
||||
}
|
||||
|
||||
// (See last comment): Wrap the above exceptions in the SWIG way.
|
||||
|
||||
namespace sgpem {
|
||||
|
||||
/** Don't get worried, order is not important! */
|
||||
|
@ -158,29 +167,75 @@ namespace sgpem {
|
|||
}
|
||||
}; //~ class Schedulable
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
// Instantiate a Thread* vector for usage with Process
|
||||
// std::out_of_range should be automatically defined,
|
||||
// see Swig manual at the STL Vector §.
|
||||
namespace std {
|
||||
%template(ThreadVector) vector<Thread*>;
|
||||
}
|
||||
|
||||
class Process : public virtual Schedulable
|
||||
{
|
||||
public:
|
||||
virtual std::vector<Thread*> get_threads();
|
||||
} //~ class Process
|
||||
|
||||
class Thread : public virtual Schedulable
|
||||
{
|
||||
public:
|
||||
virtual Process& get_process();
|
||||
} //~ class Thread
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
class SchedulableQueue
|
||||
class ReadyQueue
|
||||
{
|
||||
public:
|
||||
unsigned int size() const;
|
||||
const sgpem::Schedulable* get_item_at(const unsigned int&) const;
|
||||
void swap(unsigned int positionA, unsigned int positionB) throw();
|
||||
|
||||
typedef unsigned int position;
|
||||
typedef unsigned int size_t;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
// Dynamic cast to Process or to Thread so
|
||||
// that Python code sees the extra-methods
|
||||
%typename(out) sgpem::Schedulable*;
|
||||
{
|
||||
// OMG, Ponies!!
|
||||
Process* proc;
|
||||
Thread* thread;
|
||||
if((proc = dynamic_cast<Process*>($1)) != NULL)
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr(proc),
|
||||
SWIGTYPE_p_sgpem__Process, 0 | 0 );
|
||||
else if((thread = dynamic_cast<Thread*>($1)) != NULL)
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr(thread),
|
||||
SWIGTYPE_p_sgpem__Thread, 0 | 0 );
|
||||
else // Fall back to Schedulable* if no dynamic_cast went well:
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr(thread),
|
||||
$1_descriptor, 0 | 0 );
|
||||
}
|
||||
|
||||
sgpem::Schedulable* get_item_at(position index);
|
||||
|
||||
%typename(out) sgpem::Schedulable*;
|
||||
|
||||
void swap(position a, position b) throw(std::out_of_range);
|
||||
|
||||
private:
|
||||
// Avoid instantiation and copy
|
||||
SchedulableQueue();
|
||||
SchedulableQueue(const SchedulableQueue&);
|
||||
SchedulableQueue& operator=(const SchedulableQueue&);
|
||||
~SchedulableQueue();
|
||||
}; //~ class Schedulable
|
||||
// Avoid instantiation and copy
|
||||
ReadyQueue();
|
||||
ReadyQueue(const ReadyQueue&);
|
||||
ReadyQueue& operator=(const ReadyQueue&);
|
||||
~ReadyQueue();
|
||||
}; //~ class ReadyQueue
|
||||
|
||||
// ---------------------------------------------
|
||||
class Scheduler {
|
||||
public:
|
||||
sgpem::Policy& get_policy();
|
||||
static sgpem::Scheduler& get_instance();
|
||||
sgpem::SchedulableQueue* get_ready_queue();
|
||||
sgpem::ReadyQueue* get_ready_queue();
|
||||
private:
|
||||
Scheduler();
|
||||
~Scheduler();
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
|
||||
#include "../python_policy_manager.hh"
|
||||
#include "../python_policy.hh"
|
||||
|
||||
#include "global_preferences.hh"
|
||||
#include "schedulable_queue.hh"
|
||||
#include "ready_queue.hh"
|
||||
#include "scheduler.hh"
|
||||
#include "user_interrupt_exception.hh"
|
||||
|
||||
|
@ -114,7 +115,7 @@ main(int argc, char** argv)
|
|||
|
||||
try
|
||||
{
|
||||
SchedulableQueue sl;
|
||||
ReadyQueue sl;
|
||||
polman.test_init("python_loader_sort_queue");
|
||||
polman.get_policy().sort_queue();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue