[pypy-svn] r29030 - in pypy/dist/pypy/objspace: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Jun 20 20:42:04 CEST 2006


Author: pedronis
Date: Tue Jun 20 20:42:02 2006
New Revision: 29030

Modified:
   pypy/dist/pypy/objspace/logic.py
   pypy/dist/pypy/objspace/test/test_logicobjspace.py
Log:
try to avoid having two of the uthread scheduling loops just going back and forth among themself



Modified: pypy/dist/pypy/objspace/logic.py
==============================================================================
--- pypy/dist/pypy/objspace/logic.py	(original)
+++ pypy/dist/pypy/objspace/logic.py	Tue Jun 20 20:42:02 2006
@@ -43,6 +43,7 @@
             self.runnable_uthreads = {}
             self.uthreads_blocked_on = {}
             self.uthreads_blocked_byneed = {}
+            self.exhausting = 0
 
         def pop_runnable_thread(self):
             # umpf, no popitem in RPython
@@ -131,11 +132,16 @@
         current = AppCoroutine.w_getcurrent(space)
         schedule_state.add_to_runnable(current)
         coro.w_switch()
-        while schedule_state.have_runnable_threads():
-            next_coro = schedule_state.pop_runnable_thread()
-            if next_coro.is_alive() and next_coro != current:
-                schedule_state.add_to_runnable(current)
-                next_coro.w_switch()
+        if not schedule_state.exhausting:
+            schedule_state.exhausting += 1
+            while schedule_state.have_runnable_threads():
+                next_coro = schedule_state.pop_runnable_thread()
+                if next_coro.is_alive() and next_coro is not current:
+                    schedule_state.add_to_runnable(current)
+                    next_coro.w_switch()
+                    if schedule_state.exhausting > 1:
+                        break
+            schedule_state.exhausting -= 1
         return w_Result
     app_uthread = gateway.interp2app(uthread, unwrap_spec=[baseobjspace.ObjSpace,
                                                            baseobjspace.W_Root,
@@ -816,12 +822,15 @@
         import os
         # make sure that _stackless is imported
         w_modules = space.getbuiltinmodule('_stackless')
+        # xxx use the new startup/finish machinary for this
         def exitfunc():
             current = AppCoroutine.w_getcurrent(space)
+            schedule_state.exhausting = 2
             while schedule_state.have_runnable_threads():
                 next_coro = schedule_state.pop_runnable_thread()
                 if next_coro.is_alive() and next_coro != current:
                     schedule_state.add_to_runnable(current)
+                    print "FINISH_SCHED_SWITCH"
                     next_coro.w_switch()
                     schedule_state.remove_from_runnable(current)
             if schedule_state.have_blocked_threads():

Modified: pypy/dist/pypy/objspace/test/test_logicobjspace.py
==============================================================================
--- pypy/dist/pypy/objspace/test/test_logicobjspace.py	(original)
+++ pypy/dist/pypy/objspace/test/test_logicobjspace.py	Tue Jun 20 20:42:02 2006
@@ -270,7 +270,7 @@
         wait(T)
         assert T == 45
 
-    def notest_nested_threads(self):
+    def test_nested_threads(self):
         """check that a wait nested in a tree of
            threads works correctly
         """



More information about the Pypy-commit mailing list