- Partial attempt at fixing PythonPolicies broken return values

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@525 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-03-10 14:54:24 +00:00
parent 50a5214bb9
commit 3b593e00ae
5 changed files with 54 additions and 44 deletions

View file

@ -1,13 +1,6 @@
import mutex, thread
import sgpem
## Var Global syncronization object
_g_mutex = mutex.mutex()
## @var Synchronized return value you can read from C++
# when a threaded function returns
_ret_val = None
## @brief This is an adapter class which acts as a proxy
# for user-implemented policies
#
@ -28,7 +21,13 @@ class ScriptAdapter :
## @var The event to pass to Policy.sort_queue() after the asynchronous call
_event = None
## @var Synchronized return value you can read from C++
# when a threaded function returns
_ret_val = None
## Var Testable syncronization object
_g_mutex = mutex.mutex()
## @brief Constructor of ScriptAdapter
#
@ -43,7 +42,7 @@ class ScriptAdapter :
#
# @param self The caller object
def async_configure(self):
_g_mutex.lock(ScriptAdapter._wrap_configure, self )
self._g_mutex.lock(ScriptAdapter._wrap_configure, self )
def _wrap_configure(self):
thread.start_new_thread(ScriptAdapter._wrap_configure_callback, (self,))
@ -51,7 +50,7 @@ class ScriptAdapter :
def _wrap_configure_callback(self):
# call configure method
self._policy.configure()
_g_mutex.unlock()
self._g_mutex.unlock()
## @brief Asynchronously call Policy.sort_queue()
@ -63,7 +62,7 @@ class ScriptAdapter :
# @param event The event to pass to sort_queue
def async_sort_queue(self, event):
self._event = event
_g_mutex.lock(ScriptAdapter._wrap_sort_queue, self)
self._g_mutex.lock(ScriptAdapter._wrap_sort_queue, self)
def _wrap_sort_queue(self):
thread.start_new_thread(ScriptAdapter._wrap_sort_queue_callback,
@ -73,7 +72,7 @@ class ScriptAdapter :
# here we retrieve and pass the ready queue
queue = sgpem.Scheduler.get_instance().get_ready_queue()
self._policy.sort_queue(event, queue)
_g_mutex.unlock()
self._g_mutex.unlock()
## @brief Asynchronously call Policy.is_preemptive()
@ -86,19 +85,25 @@ class ScriptAdapter :
thread.start_new_thread(ScriptAdapter._wrap_is_preemptive_callback, (self,))
def _wrap_is_preemptive_callback(self):
_ret_val = self._policy.is_preemptive()
_g_mutex.unlock()
self._ret_val = self._policy.is_preemptive()
self._g_mutex.unlock()
## @brief Asynchronously call Policy.get_time_slice()
#
# @param self The caller object
def async_get_time_slice(self):
_g_mutex.lock(ScriptAdapter._wrap_get_time_slice, self)
self._g_mutex.lock(ScriptAdapter._wrap_get_time_slice, self)
def _wrap_get_time_slice(self):
thread.start_new_thread(ScriptAdapter._wrap_get_time_slice_callback, (self,))
def _wrap_get_time_slice_callback(self):
_ret_val = self._policy.get_time_slice()
_g_mutex.unlock()
self._ret_val = self._policy.get_time_slice()
self._g_mutex.unlock()
## @brief Return the global shared variable with the methods' last return value
def get_return_value(self):
return self._ret_val
def test_lock(self):
return self._g_mutex.test()