Commits

Armin Rigo committed 4c16a18

Try to revert module/signal and use a 'stm_dont_track_raw_accesses'
flag on the result of pypysig_getaddr_occurred() instead.

Comments (0)

Files changed (6)

pypy/interpreter/executioncontext.py

             self.fired_actions.append(action)
             # set the ticker to -1 in order to force action_dispatcher()
             # to run at the next possible bytecode
-            self.reset_ticker(-1)
+            self.rearm_ticker()
 
     def register_periodic_action(self, action, use_bytecode_counter):
         """NOT_RPYTHON:
         elif interval > MAX:
             interval = MAX
         self.checkinterval_scaled = interval * TICK_COUNTER_STEP
-        self.reset_ticker(-1)
+        self.rearm_ticker()
         if self.setcheckinterval_callback is not None:
             self.setcheckinterval_callback()
 
     def reset_ticker(self, value):
         self._ticker = value
 
+    def rearm_ticker(self):
+        self._ticker = -1
+
     def decrement_ticker(self, by):
         value = self._ticker
         if self.has_bytecode_counter:    # this 'if' is constant-folded

pypy/module/signal/__init__.py

         space.check_signal_action = interp_signal.CheckSignalAction(space)
         space.actionflag.register_periodic_action(space.check_signal_action,
                                                   use_bytecode_counter=False)
-        #
-        if space.config.translation.stm:
-            from pypy.module.signal.stmactionflag import SignalActionFlag
-        else:
-            from pypy.module.signal.actionflag import SignalActionFlag
-        space.actionflag.__class__ = SignalActionFlag
+        space.actionflag.__class__ = interp_signal.SignalActionFlag
         # xxx yes I know the previous line is a hack

pypy/module/signal/actionflag.py

-from pypy.interpreter.executioncontext import AbstractActionFlag
-from rpython.rlib import jit
-from rpython.rlib.rsignal import pypysig_getaddr_occurred
-
-
-class SignalActionFlag(AbstractActionFlag):
-    # This class uses the C-level pypysig_counter variable as the tick
-    # counter.  The C-level signal handler will reset it to -1 whenever
-    # a signal is received.  This causes CheckSignalAction.perform() to
-    # be called.
-
-    def get_ticker(self):
-        p = pypysig_getaddr_occurred()
-        return p.c_value
-
-    def reset_ticker(self, value):
-        p = pypysig_getaddr_occurred()
-        p.c_value = value
-
-    def rearm_ticker(self):
-        p = pypysig_getaddr_occurred()
-        p.c_value = -1
-
-    def decrement_ticker(self, by):
-        p = pypysig_getaddr_occurred()
-        value = p.c_value
-        if self.has_bytecode_counter:    # this 'if' is constant-folded
-            if jit.isconstant(by) and by == 0:
-                pass     # normally constant-folded too
-            else:
-                value -= by
-                p.c_value = value
-        return value

pypy/module/signal/interp_signal.py

 import sys
 
 from pypy.interpreter.error import OperationError, exception_from_errno
-from pypy.interpreter.executioncontext import AsyncAction, PeriodicAsyncAction
+from pypy.interpreter.executioncontext import (AsyncAction, AbstractActionFlag,
+    PeriodicAsyncAction)
 from pypy.interpreter.gateway import unwrap_spec
 
 from rpython.rlib import jit, rposix, rgc
 WIN32 = sys.platform == 'win32'
 
 
+class SignalActionFlag(AbstractActionFlag):
+    # This class uses the C-level pypysig_counter variable as the tick
+    # counter.  The C-level signal handler will reset it to -1 whenever
+    # a signal is received.  This causes CheckSignalAction.perform() to
+    # be called.
+
+    def get_ticker(self):
+        p = pypysig_getaddr_occurred()
+        return p.c_value
+
+    def reset_ticker(self, value):
+        # STM: explicit manipulation of the counter needs to turn the
+        # transaction inevitable.  We don't turn it inevitable in
+        # decrement_ticker() or if a real signal is received, but
+        # we turn it inevitable when this condition is detected
+        # and we reset a value >= 0.
+        pypysig_set_occurred(value)
+
+    def rearm_ticker(self):
+        p = pypysig_getaddr_occurred()
+        p.c_value = -1
+
+    def decrement_ticker(self, by):
+        p = pypysig_getaddr_occurred()
+        value = p.c_value
+        if self.has_bytecode_counter:    # this 'if' is constant-folded
+            if jit.isconstant(by) and by == 0:
+                pass     # normally constant-folded too
+            else:
+                value -= by
+                p.c_value = value
+        return value
+
+
 class CheckSignalAction(PeriodicAsyncAction):
     """An action that is automatically invoked when a signal is received."""
 
                              space.wrap("invalid signal value"))
     if not space.threadlocals.signals_enabled():
         raise OperationError(space.w_ValueError,
-                             space.wrap("signal() only works in main thread "
+                             space.wrap("signal only works in main thread "
                                  "or with __pypy__.thread.enable_signals()"))
     check_signum_in_range(space, signum)
 
     if not space.threadlocals.signals_enabled():
         raise OperationError(
             space.w_ValueError,
-            space.wrap("set_wakeup_fd() only works in main thread "
+            space.wrap("set_wakeup_fd only works in main thread "
                        "or with __pypy__.thread.enable_signals()"))
     old_fd = pypysig_set_wakeup_fd(fd)
     return space.wrap(intmask(old_fd))

pypy/module/signal/stmactionflag.py

-from pypy.interpreter.executioncontext import AbstractActionFlag
-from rpython.rlib import jit, rstm
-from rpython.rlib.objectmodel import we_are_translated
-from rpython.rlib.rsignal import pypysig_get_occurred, pypysig_set_occurred
-
-
-class SignalActionFlag(AbstractActionFlag):
-    # This is mostly a copy of actionflag.py, but written in a way
-    # that doesn't force atomic transactions --- but isn't very JIT
-    # friendly yet.
-
-    def get_ticker(self):
-        if we_are_translated():
-            return pypysig_get_occurred()
-        else:
-            return 42
-
-    def reset_ticker(self, value):
-        if we_are_translated():
-            # explicit manipulation of the counter needs to turn the
-            # transaction inevitable.  We don't turn it inevitable in
-            # decrement_ticker() or if a real signal is received, but
-            # we turn it inevitable when this condition is detected
-            # and we reset a value >= 0.
-            rstm.become_inevitable()
-            pypysig_set_occurred(value)
-
-    def rearm_ticker(self):
-        if we_are_translated():
-            pypysig_set_occurred(-1)
-
-    def decrement_ticker(self, by):
-        if we_are_translated():
-            value = pypysig_get_occurred()
-            if self.has_bytecode_counter:    # this 'if' is constant-folded
-                if jit.isconstant(by) and by == 0:
-                    pass     # normally constant-folded too
-                else:
-                    value -= by
-                    pypysig_set_occurred(value)
-            return value
-        else:
-            return 42

rpython/rlib/rsignal.py

 
 # don't use rffi.LONGP because the JIT doesn't support raw arrays so far
 struct_name = 'pypysig_long_struct'
-LONG_STRUCT = lltype.Struct(struct_name, ('c_value', lltype.Signed),
-                            hints={'c_name' : struct_name, 'external' : 'C'})
+_LONG_STRUCT = lltype.Struct(struct_name, ('c_value', lltype.Signed),
+                             hints={'c_name' : struct_name, 'external' : 'C',
+                                    'stm_dont_track_raw_accesses': True})
 del struct_name
 
 pypysig_getaddr_occurred = external('pypysig_getaddr_occurred', [],
-                                    lltype.Ptr(LONG_STRUCT), _nowrapper=True,
+                                    lltype.Ptr(_LONG_STRUCT), _nowrapper=True,
                                     transactionsafe=True,
                                     elidable_function=True)
 pypysig_get_occurred = external('pypysig_get_occurred', [], lltype.Signed,
                                 _nowrapper=True,
                                 transactionsafe=True)
 pypysig_set_occurred = external('pypysig_set_occurred', [lltype.Signed],
-                                lltype.Void, _nowrapper=True,
-                                transactionsafe=True)
+                                lltype.Void, _nowrapper=True)
 c_alarm = external('alarm', [rffi.INT], rffi.INT)
 c_pause = external('pause', [], rffi.INT, threadsafe=True)
 c_siginterrupt = external('siginterrupt', [rffi.INT, rffi.INT], rffi.INT)