From 9471870adb9ec4b0d5f67e7aef2aad6169f8994e Mon Sep 17 00:00:00 2001 From: tchernobog Date: Tue, 21 Feb 2006 15:18:13 +0000 Subject: [PATCH] - Added initial interface for the PythonScript adapter git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@371 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/pyloader/ScriptAdapter.py | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/backend/pyloader/ScriptAdapter.py diff --git a/src/backend/pyloader/ScriptAdapter.py b/src/backend/pyloader/ScriptAdapter.py new file mode 100644 index 0000000..9d72903 --- /dev/null +++ b/src/backend/pyloader/ScriptAdapter.py @@ -0,0 +1,68 @@ +import mutex, thread + +_g_mutex = mutex.mutex() + +## @brief This is an adapter class which will dinamically +# inherit from the user-defined policy +# +# At runtime, this class will inherit from the user-defined +# policy, and act as a proxy for scheduler calls. It is quite +# useful also to prevent a potentially infinite-looping +# policy to indefinitely hanging the program. +# +# Instantiated in the C++ code, it should be prepared before use +# like this: +# @code +# '''Please note the ending comma''' +# ScriptAdapter.__bases__ = UserPolicy, +# policy_adapter = ScriptAdapter() +# @endcode +class ScriptAdapter : + def __init__(self): + pass; + + def async_configure(self): + _g_mutex.lock(_wrap_configure, self) + + def _wrap_configure(self): + thread.start_new_thread(_wrap_configure_callback, (self)) + + def _wrap_configure_callback(self): + self.configure() + _g_mutex.unlock() + + def async_sort_queue(self): + _g_mutex.lock(_wrap_sort_queue, self) + + def _wrap_sort_queue(self): + thread.start_new_thread(_wrap_sort_queue_callback, (self)) + + def _wrap_sort_queue_callback(self): + # here we should write the code to pass queue and event to + # the inherited method + self.sort_queue() + _g_mutex.unlock() + + def async_is_preemptible(self): + _g_mutex.lock(_wrap_is_preemptible, self); + + def _wrap_is_preemptible(self): + thread.start_new_thread(_wrap_is_preemptible_callback, (self)) + + def _wrap_is_preemptible_callback(self): + # here we should return the call value + self.is_preemptible() + _g_mutex.unlock() + + def async_is_timesliced(self): + _g_mutex.lock(_wrap_is_timesliced, self) + + def _wrap_is_timesliced(self): + thread.start_new_thread(_wrap_is_timesliced_callback, (self)) + + def _wrap_is_timesliced_callback(self): + # return value! + self.is_timesliced() + _g_mutex.unlock() + +