- 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:
parent
876fb85614
commit
dfe1593b44
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
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);
|
||||
bool still_locked = static_cast<bool>(PyInt_AsLong(retval));
|
||||
still_locked = static_cast<bool>(PyInt_AsLong(retval));
|
||||
Py_DECREF(retval);
|
||||
|
||||
if(still_locked)
|
||||
throw UserInterruptException("User-defined policy is taking too long to terminate.");
|
||||
if(i++ > 120)
|
||||
throw UserInterruptException("User-defined policy is "
|
||||
"taking too long to terminate.");
|
||||
} while(still_locked);
|
||||
|
||||
|
||||
// What we should really do here:
|
||||
/* do {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue