[pypy-svn] r78734 - in pypy/branch/signals/pypy: interpreter module/signal module/thread module/thread/test

arigo at codespeak.net arigo at codespeak.net
Fri Nov 5 13:33:29 CET 2010


Author: arigo
Date: Fri Nov  5 13:33:26 2010
New Revision: 78734

Modified:
   pypy/branch/signals/pypy/interpreter/executioncontext.py
   pypy/branch/signals/pypy/module/signal/interp_signal.py
   pypy/branch/signals/pypy/module/thread/gil.py
   pypy/branch/signals/pypy/module/thread/test/test_gil.py
Log:
Fix the thread tests.


Modified: pypy/branch/signals/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/signals/pypy/interpreter/executioncontext.py	(original)
+++ pypy/branch/signals/pypy/interpreter/executioncontext.py	Fri Nov  5 13:33:26 2010
@@ -414,13 +414,13 @@
         self.space.actionflag.fire(self)
 
     def fire_after_thread_switch(self):
-        XXX
         """Bit of a hack: fire() the action but only the next time the GIL
         is released and re-acquired (i.e. after a potential thread switch).
-        Don't call this if threads are not enabled.
+        Don't call this if threads are not enabled.  Currently limited to
+        one action (i.e. reserved for CheckSignalAction from module/signal).
         """
         from pypy.module.thread.gil import spacestate
-        spacestate.set_actionflag_bit_after_thread_switch |= self.bitmask
+        spacestate.action_after_thread_switch = self
 
     def perform(self, executioncontext, frame):
         """To be overridden."""

Modified: pypy/branch/signals/pypy/module/signal/interp_signal.py
==============================================================================
--- pypy/branch/signals/pypy/module/signal/interp_signal.py	(original)
+++ pypy/branch/signals/pypy/module/signal/interp_signal.py	Fri Nov  5 13:33:26 2010
@@ -82,7 +82,6 @@
             # need a helper action in case signals arrive in a non-main thread
             self.pending_signals = {}
             self.reissue_signal_action = ReissueSignalAction(space)
-            space.actionflag.register_action(self.reissue_signal_action)
         else:
             self.reissue_signal_action = None
 

Modified: pypy/branch/signals/pypy/module/thread/gil.py
==============================================================================
--- pypy/branch/signals/pypy/module/thread/gil.py	(original)
+++ pypy/branch/signals/pypy/module/thread/gil.py	Fri Nov  5 13:33:26 2010
@@ -20,7 +20,8 @@
 
     def initialize(self, space):
         # add the GIL-releasing callback as an action on the space
-        space.actionflag.register_action(GILReleaseAction(space))
+        space.actionflag.register_periodic_action(GILReleaseAction(space),
+                                                  use_bytecode_counter=True)
 
     def setup_threads(self, space):
         """Enable threads in the object space, if they haven't already been."""
@@ -44,7 +45,6 @@
         # test_compile_lock.  As a workaround, we repatch these global
         # fields systematically.
         spacestate.ll_GIL = self.ll_GIL
-        spacestate.actionflag = space.actionflag
         invoke_around_extcall(before_external_call, after_external_call)
         return result
 
@@ -68,18 +68,17 @@
 
     def _freeze_(self):
         self.ll_GIL = thread.null_ll_lock
-        self.actionflag = None
-        self.set_actionflag_bit_after_thread_switch = 0
+        self.action_after_thread_switch = None
+        # ^^^ set by AsyncAction.fire_after_thread_switch()
         return False
 
     def after_thread_switch(self):
         # this is support logic for the signal module, to help it deliver
         # signals to the main thread.
-        actionflag = self.actionflag
-        if actionflag is not None:
-            flag = actionflag.get()
-            flag |= self.set_actionflag_bit_after_thread_switch
-            actionflag.set(flag)
+        action = self.action_after_thread_switch
+        if action is not None:
+            self.action_after_thread_switch = None
+            action.fire()
 
 spacestate = SpaceState()
 spacestate._freeze_()

Modified: pypy/branch/signals/pypy/module/thread/test/test_gil.py
==============================================================================
--- pypy/branch/signals/pypy/module/thread/test/test_gil.py	(original)
+++ pypy/branch/signals/pypy/module/thread/test/test_gil.py	Fri Nov  5 13:33:26 2010
@@ -8,7 +8,7 @@
     pass
 
 class FakeActionFlag(object):
-    def register_action(self, action):
+    def register_periodic_action(self, action, use_bytecode_counter):
         pass
     def get(self):
         return 0



More information about the Pypy-commit mailing list