diff --git a/src/backend/pyloader/Policy.py b/src/backend/pyloader/Policy.py index 3b8206f..e30cffc 100644 --- a/src/backend/pyloader/Policy.py +++ b/src/backend/pyloader/Policy.py @@ -154,7 +154,7 @@ class Policy: # @param b The partition ending element position in the queue # @param cmpf The binary function to use for comparing two elements # @return The new pivot index - def __partition_(self, queue, a, b, cmpf): + def __partition(self, queue, a, b, cmpf): # takes pivot element: right = queue.get_item_at(b) i = a diff --git a/src/backend/pyloader/python_policy.cc b/src/backend/pyloader/python_policy.cc index 1280653..7ebc17e 100644 --- a/src/backend/pyloader/python_policy.cc +++ b/src/backend/pyloader/python_policy.cc @@ -162,18 +162,24 @@ void PythonPolicy::wait_unlock() const throw(UserInterruptException) { PyThreadState *_save; - Py_UNBLOCK_THREADS - sleep(2); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! - Py_BLOCK_THREADS + int i = 0; // We give the sort_queue() three seconds max time, then... + // we shot it stone dead! Bang. - // Now check if lock has been released, else - // throw an exception - PyObject* retval = PyObject_CallMethod(_lock, "test", NULL); - bool still_locked = static_cast(PyInt_AsLong(retval)); - Py_DECREF(retval); + bool still_locked; + do { + Py_UNBLOCK_THREADS; + usleep(25000); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! + Py_BLOCK_THREADS; + + PyObject* retval = PyObject_CallMethod(_lock, "test", NULL); + still_locked = static_cast(PyInt_AsLong(retval)); + Py_DECREF(retval); + + if(i++ > 120) + throw UserInterruptException("User-defined policy is " + "taking too long to terminate."); + } while(still_locked); - if(still_locked) - throw UserInterruptException("User-defined policy is taking too long to terminate."); // What we should really do here: /* do { diff --git a/src/backend/pyloader/sgpem.i b/src/backend/pyloader/sgpem.i index 9779c03..fada4f8 100644 --- a/src/backend/pyloader/sgpem.i +++ b/src/backend/pyloader/sgpem.i @@ -14,12 +14,34 @@ * 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 { class Policy { public: virtual ~Policy() = 0; - PolicyParameters& get_parameters(); + sgpem::PolicyParameters& get_parameters(); }; // -------------------------------------------- @@ -127,7 +149,7 @@ namespace sgpem { { public: 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(); private: @@ -157,14 +179,14 @@ namespace sgpem { void give_cpu_time(const int& time); int get_last_scheduled() const; state get_state() const; - const Schedulable* get_schedulable() const; + const sgpem::Schedulable* get_schedulable() const; }; // --------------------------------------------- class Scheduler { public: - static Scheduler& get_instance(); - SchedulableList* get_ready_queue(); + static sgpem::Scheduler& get_instance(); + sgpem::SchedulableList* get_ready_queue(); private: Scheduler(); ~Scheduler(); diff --git a/src/builtin-policies/fcfs.py b/src/builtin-policies/fcfs.py index a39f7d1..ad7fcd2 100644 --- a/src/builtin-policies/fcfs.py +++ b/src/builtin-policies/fcfs.py @@ -1,4 +1,5 @@ from Policy import Policy +import sys class fcfs(Policy) : def __init__(self): @@ -15,19 +16,12 @@ class fcfs(Policy) : def sort_queue(self, event, queue): print 'Entering sort_queue' - print queue.size() - print queue.get_item_at(0) - print dir(queue.get_item_at(0)) - for i in range(0, queue.size()): - ss = queue.get_item_at(i) - print ss.get_schedulable().get_name() - # Uncomment this to try the qsort algorithm with FCFS - #cmpf = lambda a, b: \ - # 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 + cmpf = lambda a, b: \ + 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