- Tadaaaan! Fixed it! Now:

- SWIG generate interface doesn't do a mess with namespaces anymore
  - Improved PythonPolicy to be acceptably faster
  - FCFS implemented, sir!
  - FIXME : the qsort implementation doesn't seem right


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@413 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-23 21:50:43 +00:00
parent 876fb85614
commit dfe1593b44
4 changed files with 53 additions and 31 deletions

View File

@ -154,7 +154,7 @@ class Policy:
# @param b The partition ending 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 # @param cmpf The binary function to use for comparing two elements
# @return The new pivot index # @return The new pivot index
def __partition_(self, queue, a, b, cmpf): def __partition(self, queue, a, b, cmpf):
# takes pivot element: # takes pivot element:
right = queue.get_item_at(b) right = queue.get_item_at(b)
i = a i = a

View File

@ -162,18 +162,24 @@ void
PythonPolicy::wait_unlock() const throw(UserInterruptException) PythonPolicy::wait_unlock() const throw(UserInterruptException)
{ {
PyThreadState *_save; PyThreadState *_save;
Py_UNBLOCK_THREADS int i = 0; // We give the sort_queue() three seconds max time, then...
sleep(2); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! // we shot it stone dead! Bang.
Py_BLOCK_THREADS
bool still_locked;
do {
Py_UNBLOCK_THREADS;
usleep(25000); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
Py_BLOCK_THREADS;
// Now check if lock has been released, else
// throw an exception
PyObject* retval = PyObject_CallMethod(_lock, "test", NULL); PyObject* retval = PyObject_CallMethod(_lock, "test", NULL);
bool still_locked = static_cast<bool>(PyInt_AsLong(retval)); still_locked = static_cast<bool>(PyInt_AsLong(retval));
Py_DECREF(retval); Py_DECREF(retval);
if(still_locked) if(i++ > 120)
throw UserInterruptException("User-defined policy is taking too long to terminate."); throw UserInterruptException("User-defined policy is "
"taking too long to terminate.");
} while(still_locked);
// What we should really do here: // What we should really do here:
/* do { /* do {

View File

@ -14,12 +14,34 @@
* the sgpem user manual) * the sgpem user manual)
*/ */
/** 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.
*/
namespace std {
class exception {
public:
virtual const char* what() const throw();
private:
exception();
};
class runtime_error : public std::exception {
public:
virtual const char* what() const throw();
private:
runtime_error();
};
}
namespace sgpem { namespace sgpem {
class Policy { class Policy {
public: public:
virtual ~Policy() = 0; virtual ~Policy() = 0;
PolicyParameters& get_parameters(); sgpem::PolicyParameters& get_parameters();
}; };
// -------------------------------------------- // --------------------------------------------
@ -127,7 +149,7 @@ namespace sgpem {
{ {
public: public:
unsigned int size() const; unsigned int size() const;
const SchedulableStatus* get_item_at(const unsigned int&) const; const sgpem::SchedulableStatus* get_item_at(const unsigned int&) const;
void swap(unsigned int positionA, unsigned int positionB) throw(); void swap(unsigned int positionA, unsigned int positionB) throw();
private: private:
@ -157,14 +179,14 @@ namespace sgpem {
void give_cpu_time(const int& time); void give_cpu_time(const int& time);
int get_last_scheduled() const; int get_last_scheduled() const;
state get_state() const; state get_state() const;
const Schedulable* get_schedulable() const; const sgpem::Schedulable* get_schedulable() const;
}; };
// --------------------------------------------- // ---------------------------------------------
class Scheduler { class Scheduler {
public: public:
static Scheduler& get_instance(); static sgpem::Scheduler& get_instance();
SchedulableList* get_ready_queue(); sgpem::SchedulableList* get_ready_queue();
private: private:
Scheduler(); Scheduler();
~Scheduler(); ~Scheduler();

View File

@ -1,4 +1,5 @@
from Policy import Policy from Policy import Policy
import sys
class fcfs(Policy) : class fcfs(Policy) :
def __init__(self): def __init__(self):
@ -15,19 +16,12 @@ class fcfs(Policy) :
def sort_queue(self, event, queue): def sort_queue(self, event, queue):
print 'Entering sort_queue' print 'Entering sort_queue'
print queue.size() cmpf = lambda a, b: \
print queue.get_item_at(0) a.get_schedulable().get_arrival_time() < \
print dir(queue.get_item_at(0)) b.get_schedulable().get_arrival_time()
for i in range(0, queue.size()): try:
ss = queue.get_item_at(i) self.sort(queue,cmpf)
print ss.get_schedulable().get_name() except:
# Uncomment this to try the qsort algorithm with FCFS print "Unexpected error:", sys.exc_info()[0]
#cmpf = lambda a, b: \ raise
# a.get_schedulable().get_arrival_time() < \
# b.get_schedulable().get_arrival_time()
#try:
# self.sort(queue,cmpf)
#except:
# print "Unexpected error:", sys.exc_info()[0]
# raise