diff --git a/ChangeLog b/ChangeLog index ec6d8fa..57ac83e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,67 @@ +2006-02-23 10:12 tchernobog + + * trunk/src/backend/pyloader/Policy.py, + trunk/src/backend/pyloader/ScriptAdapter.py, + trunk/src/backend/pyloader/python_policy.cc, + trunk/src/backend/schedulable_list.hh, trunk/src/backend/sgpem.i: + - Previous segmentation fault was due to a faulty call (wrong + parameters to ScriptAdapter.__wrap_sort_queue()). Now prints an + error and check for retval before Py_DECREF'ing it. - Fix(?) qsort + implementation in Policy - SWIG doesn't understand "uint". Change + into more verbose (but surely standard) unsigned int + +2006-02-23 09:26 tchernobog + + * trunk/Makefile.am, trunk/doc/sgpem2uman.texi, + trunk/src/backend/pyloader/python_policy.cc: - Add note that + building with --disable-shared at the moment doesn't work + +2006-02-22 23:21 fpaparel + + * trunk/src/backend/schedulable_list.hh: - hemm... updated also the + header!! + +2006-02-22 23:19 fpaparel + + * trunk/src/backend/schedulable_list.cc: - implemented swap in + schedulable_list.cc + +2006-02-22 22:57 tchernobog + + * trunk/src/backend/policy.hh, trunk/src/backend/pyloader/Policy.py, + trunk/src/backend/pyloader/python_policy_manager.cc, + trunk/src/backend/sgpem.i, trunk/src/builtin-policies/fcfs.py, + trunk/src/testsuite/test-python_loader.cc: - Implement first draft + of quicksort in Python - Extend test to have a set of processes + (now lacks significative output) - Extend FCFS policy to do + something useful - FIXME : segfaults on sortQueue() - FIXME : + needs implementation for SchedulableQueue.swap() + +2006-02-22 22:45 fpaparel + + * trunk/src/graphical_simulation.hh, + trunk/src/graphical_terminal_io.cc, + trunk/src/graphical_terminal_io.hh, trunk/src/main.cc, + trunk/src/start_gui.cc, trunk/src/start_gui.hh, + trunk/src/text_simulation.cc, trunk/src/text_simulation.hh: - The + grafical interpreter now works + +2006-02-22 21:35 tchernobog + + * trunk/src/backend/pyloader/Policy.py, + trunk/src/backend/schedulable_list.hh, trunk/src/backend/sgpem.i: + - Add swap() method signature to SchedulableQueue - Export swap() + to SWIG - Add sort function (just its documentation, actually, + implementation will follow) to Policy.py + +2006-02-22 20:36 tchernobog + + * trunk/ChangeLog, trunk/Makefile.am, + trunk/src/backend/pyloader/python_policy.cc, + trunk/src/backend/pyloader/python_policy_manager.cc: - "Yeehaw! + It's working! I can't believe it! And they said that an imitation + diamond wasn't good enough..." :-) + 2006-02-22 15:16 tchernobog * trunk/src/backend/dummy_policy.hh, trunk/src/backend/policy.hh, diff --git a/Makefile.am b/Makefile.am index a0dd0a4..0bc9321 100644 --- a/Makefile.am +++ b/Makefile.am @@ -183,7 +183,8 @@ src_backend_libbackend_la_SOURCES = \ src/backend/schedulable_status.cc \ src/backend/scheduler.cc \ src/backend/slice.cc \ - src/backend/string_utils.cc + src/backend/string_utils.cc \ + src/backend/user_interrupt_exception.cc noinst_HEADERS += \ src/backend/dummy_policy.hh \ @@ -198,7 +199,8 @@ noinst_HEADERS += \ src/backend/schedulable_status.hh \ src/backend/scheduler.hh \ src/backend/slice.hh \ - src/backend/string_utils.hh + src/backend/string_utils.hh \ + src/backend/user_interrupt_exception.hh # ############################################################ # @@ -315,14 +317,24 @@ pyc_PYTHON = \ noinst_PROGRAMS = test-python_loader +# Shouldn't need Gtkmm! This is a coding anomaly test_python_loader_CPPFLAGS = \ -I@top_srcdir@/src \ -DPYCDIR="\"$(pycdir)\"" \ -DMODDIR="\"$(moddir)\"" \ $(PYTHON_CPPFLAGS) \ - $(GLIBMM_CFLAGS) + $(GLIBMM_CFLAGS) \ + $(GTKMM_CFLAGS) \ + $(GTHREAD_CFLAGS) test_python_loader_LDFLAGS = \ - src/backend/pyloader/libpyloader.la + src/backend/pyloader/libpyloader.la \ + $(GTKMM_LIBS) $(GTHREAD_LIBS) test_python_loader_SOURCES = \ - src/testsuite/test-python_loader.cc + src/testsuite/test-python_loader.cc \ + src/start_gui.cc \ + src/standard_io.cc \ + src/text_simulation.cc \ + src/observer.cc \ + src/graphical_terminal_io.cc \ + src/simulation.cc diff --git a/src/backend/pyloader/ScriptAdapter.py b/src/backend/pyloader/ScriptAdapter.py index 623f2ec..2d2e727 100644 --- a/src/backend/pyloader/ScriptAdapter.py +++ b/src/backend/pyloader/ScriptAdapter.py @@ -52,14 +52,14 @@ class ScriptAdapter : self._policy.sort_queue(event, queue) _g_mutex.unlock() - def async_is_preemptible(self): - _g_mutex.lock(ScriptAdapter._wrap_is_preemptible, self) + def async_is_preemptive(self): + _g_mutex.lock(ScriptAdapter._wrap_is_preemptive, self) - def _wrap_is_preemptible(self): - thread.start_new_thread(ScriptAdapter._wrap_is_preemptible_callback, (self,)) + def _wrap_is_preemptive(self): + thread.start_new_thread(ScriptAdapter._wrap_is_preemptive_callback, (self,)) - def _wrap_is_preemptible_callback(self): - _ret_val = self._policy.is_preemptible() + def _wrap_is_preemptive_callback(self): + _ret_val = self._policy.is_preemptive() _g_mutex.unlock() def async_get_time_slice(self): diff --git a/src/backend/pyloader/python_policy.cc b/src/backend/pyloader/python_policy.cc index 3847b56..1280653 100644 --- a/src/backend/pyloader/python_policy.cc +++ b/src/backend/pyloader/python_policy.cc @@ -1,4 +1,4 @@ -// src/backend/python_policy.cc - Copyright 2005, 2006, University +// src/backend/pyloader/python_policy.cc - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -90,22 +90,26 @@ PythonPolicy::~PythonPolicy() void -PythonPolicy::configure() +PythonPolicy::configure() throw(UserInterruptException) { PyObject* retval = PyObject_CallMethod(_adapter, "async_configure", NULL); Py_DECREF(retval); + wait_unlock(); } void -PythonPolicy::sort_queue(Scheduler::event event) const +PythonPolicy::sort_queue(Scheduler::event event) const throw(UserInterruptException) { PyObject* pEvent = PyInt_FromLong(event); PyObject* pMethodName = PyString_FromString("async_sort_queue"); PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, pEvent, NULL); + + // Do minimal debugging if(!retval) PyErr_Print(); else Py_DECREF(retval); + Py_DECREF(pMethodName); Py_DECREF(pEvent); @@ -121,7 +125,8 @@ PythonPolicy::get_description() const bool -PythonPolicy::is_pre_emptive() const { +PythonPolicy::is_pre_emptive() const throw(UserInterruptException) +{ PyObject* retval = PyObject_CallMethod(_adapter, "async_is_preemptive", NULL); Py_DECREF(retval); @@ -134,7 +139,7 @@ PythonPolicy::is_pre_emptive() const { int -PythonPolicy::get_time_slice() const { +PythonPolicy::get_time_slice() const throw(UserInterruptException) { PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL); Py_DECREF(retval); @@ -154,11 +159,21 @@ PythonPolicy::set_time_slice(const int&) void -PythonPolicy::wait_unlock() const +PythonPolicy::wait_unlock() const throw(UserInterruptException) { PyThreadState *_save; Py_UNBLOCK_THREADS sleep(2); // 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(PyInt_AsLong(retval)); + Py_DECREF(retval); + + if(still_locked) + throw UserInterruptException("User-defined policy is taking too long to terminate."); // What we should really do here: /* do { @@ -175,5 +190,4 @@ PythonPolicy::wait_unlock() const all's went okay, can exit loop } */ - Py_BLOCK_THREADS } diff --git a/src/backend/pyloader/python_policy.hh b/src/backend/pyloader/python_policy.hh index d217156..907bc22 100644 --- a/src/backend/pyloader/python_policy.hh +++ b/src/backend/pyloader/python_policy.hh @@ -1,4 +1,4 @@ -// src/backend/python_policy.hh - Copyright 2005, 2006, University +// src/backend/pyloader/python_policy.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -29,11 +29,13 @@ #include #include "../policy.hh" +#include "../user_interrupt_exception.hh" namespace sgpem { class PythonPolicy; class PythonPolicyManager; + class UserInterruptException; class SG_DLLEXPORT PythonPolicy : public Policy { @@ -43,11 +45,13 @@ namespace sgpem virtual ~PythonPolicy(); - void configure(); - void sort_queue(Scheduler::event) const; + void configure() throw(UserInterruptException); + void sort_queue(Scheduler::event) const throw(UserInterruptException); Glib::ustring get_description() const; - bool is_pre_emptive() const; - int get_time_slice() const; + bool is_pre_emptive() const throw(UserInterruptException); + int get_time_slice() const throw(UserInterruptException); + + // Singing with Caipha's voice: "must die, must die, this method must die!" void set_time_slice(const int&); private: @@ -55,7 +59,7 @@ namespace sgpem PythonPolicy(const PythonPolicy&); PythonPolicy& operator=(const PythonPolicy&); - void wait_unlock() const; + void wait_unlock() const throw(UserInterruptException); PyObject* _adapter; PyObject* _adapter_dict; diff --git a/src/backend/pyloader/python_policy_manager.cc b/src/backend/pyloader/python_policy_manager.cc index 27936cc..93f2792 100644 --- a/src/backend/pyloader/python_policy_manager.cc +++ b/src/backend/pyloader/python_policy_manager.cc @@ -1,4 +1,4 @@ -// src/backend/python_policy_manager.cc - Copyright 2005, 2006, University +// src/backend/pyloader/python_policy_manager.cc - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -56,8 +56,10 @@ PythonPolicyManager::get_policy() void PythonPolicyManager::init() { - if(_initialized) - Py_Finalize(); + if(_initialized) { + _python_policy = std::auto_ptr(0); + Py_Finalize(); + } Py_Initialize(); _initialized = true; diff --git a/src/backend/pyloader/python_policy_manager.hh b/src/backend/pyloader/python_policy_manager.hh index d0da2d9..26b72d4 100644 --- a/src/backend/pyloader/python_policy_manager.hh +++ b/src/backend/pyloader/python_policy_manager.hh @@ -1,4 +1,4 @@ -// src/backend/python_policy_manager.hh - Copyright 2005, 2006, University +// src/backend/pyloader/python_policy_manager.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // diff --git a/src/backend/user_interrupt_exception.cc b/src/backend/user_interrupt_exception.cc new file mode 100644 index 0000000..61ea1b9 --- /dev/null +++ b/src/backend/user_interrupt_exception.cc @@ -0,0 +1,32 @@ +// src/backend/user_interrupt_exception.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +// Warning! This exception will be thrown across different libraries. +// It could be necessary to do dynamic type-checking when +// catching it (with typeinfo). + +#include "user_interrupt_exception.hh" +using namespace sgpem; + +UserInterruptException::UserInterruptException(const char* msg) + : std::runtime_error(msg) +{} + +UserInterruptException::~UserInterruptException() throw() {} diff --git a/src/backend/user_interrupt_exception.hh b/src/backend/user_interrupt_exception.hh new file mode 100644 index 0000000..d99fe21 --- /dev/null +++ b/src/backend/user_interrupt_exception.hh @@ -0,0 +1,45 @@ +// src/backend/user_interrupt_exception.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +// Warning! This exception will be thrown across different libraries. +// It could be necessary to do dynamic type-checking when +// catching it (with typeinfo). + +#ifndef USER_INTERRUPT_EXCEPTION +#define USER_INTERRUPT_EXCEPTION 1 + +#include "config.h" + +#include + +namespace sgpem { + class UserInterruptException; + + class SG_DLLEXPORT UserInterruptException : public std::runtime_error + { + public: + UserInterruptException(const char* msg = ""); + virtual ~UserInterruptException() throw (); + + private: + }; +} //~ namespace sgpem + +#endif diff --git a/src/builtin-policies/fcfs.py b/src/builtin-policies/fcfs.py index 7fbbcfe..36fc24a 100644 --- a/src/builtin-policies/fcfs.py +++ b/src/builtin-policies/fcfs.py @@ -14,7 +14,20 @@ class fcfs(Policy) : return -1 def sort_queue(self, event, queue): + print 'Entering sort_queue' + print queue.size() + 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() cmpf = lambda a, b: \ a.get_schedulable().get_arrival_time() < \ b.get_schedulable().get_arrival_time() - self.sort(queue,cmpf) + try: + self.sort(queue,cmpf) + except: + print "Unexpected error:", sys.exc_info()[0] + raise + for i in range(0, queue.size()): + ss = queue.get_item_at(i) + print ss.get_schedulable().get_name() diff --git a/src/testsuite/test-python_loader.cc b/src/testsuite/test-python_loader.cc index cea07cb..33a5dd7 100644 --- a/src/testsuite/test-python_loader.cc +++ b/src/testsuite/test-python_loader.cc @@ -27,12 +27,19 @@ #include "backend/schedulable_status.hh" #include "backend/schedulable_list.hh" #include "backend/scheduler.hh" +#include "standard_io.hh" +#include "start_gui.hh" +#include "text_simulation.hh" +#include "templates/smartp.hh" + #include int -main(int, char** ) { +main(int argc, char** argv) { using namespace sgpem; + Glib::thread_init(); + // Create an INITIAL STATE Process p1("P1", 0,5,1); Process p2("P2", 0,5,2); @@ -60,7 +67,17 @@ main(int, char** ) { PythonPolicyManager* ppm = PythonPolicyManager::get_instance(); ppm->init(); Policy& pol = ppm->get_policy(); - pol.configure(); - std::cout << pol.get_time_slice() << std::endl; - pol.sort_queue(Scheduler::event_schedulable_arrival); + Scheduler::get_instance().set_policy(&pol); + + //the textual simulation + TextSimulation text_sim; + History::get_instance().attach(&text_sim); + + //textual IO + memory::smart_ptr io(new StandardIO()); + text_sim.add_io_device(io); + text_sim.update(); + + //grafical IO + start_gui(argc, argv, text_sim); }