1. Pypy
  2. Untitled project
  3. pypy

Commits

Armin Rigo  committed 1bf6c8d

Untested so far: attempt to fix signals for stm

  • Participants
  • Parent commits 8eedaf9
  • Branches stm-thread-2

Comments (0)

Files changed (6)

File pypy/module/signal/__init__.py

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

File pypy/module/signal/actionflag.py

View file
+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

File pypy/module/signal/interp_signal.py

View file
 import sys
 
 from pypy.interpreter.error import OperationError, exception_from_errno
-from pypy.interpreter.executioncontext import (AsyncAction, AbstractActionFlag,
-    PeriodicAsyncAction)
+from pypy.interpreter.executioncontext import AsyncAction, 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):
-        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
-
-
 class CheckSignalAction(PeriodicAsyncAction):
     """An action that is automatically invoked when a signal is received."""
 

File pypy/module/signal/stmactionflag.py

View file
+from pypy.interpreter.executioncontext import AbstractActionFlag
+from rpython.rlib import jit
+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):
+        return pypysig_get_occurred()
+
+    def reset_ticker(self, value):
+        pypysig_set_occurred(value)
+
+    def rearm_ticker(self):
+        pypysig_set_occurred(-1)
+
+    def decrement_ticker(self, by):
+        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

File rpython/rlib/rsignal.py

View file
                       'pypysig_ignore', 'pypysig_setflag',
                       'pypysig_reinstall',
                       'pypysig_set_wakeup_fd',
-                      'pypysig_getaddr_occurred'],
+                      'pypysig_getaddr_occurred',
+                      'pypysig_get_occurred', 'pypysig_set_occurred'],
 )
 
 class CConfig:
                                     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)
 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)

File rpython/translator/c/src/signals.h

View file
 void *pypysig_getaddr_occurred(void);
 #define pypysig_getaddr_occurred()   ((void *)(&pypysig_counter))
 
+static long pypysig_get_occurred(void) { return pypysig_counter.value; }
+static void pypysig_set_occurred(long value) { pypysig_counter.value = value; }
+
 #endif