Author: Armin Rigo <[email protected]>
Branch: stm-thread-2
Changeset: r61318:1bf6c8d6fe7b
Date: 2013-02-16 11:35 +0100
http://bitbucket.org/pypy/pypy/changeset/1bf6c8d6fe7b/
Log: Untested so far: attempt to fix signals for stm
diff --git a/pypy/module/signal/__init__.py b/pypy/module/signal/__init__.py
--- a/pypy/module/signal/__init__.py
+++ b/pypy/module/signal/__init__.py
@@ -47,5 +47,10 @@
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
diff --git a/pypy/module/signal/actionflag.py b/pypy/module/signal/actionflag.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/signal/actionflag.py
@@ -0,0 +1,33 @@
+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
diff --git a/pypy/module/signal/interp_signal.py
b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -4,8 +4,7 @@
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
@@ -18,36 +17,6 @@
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."""
diff --git a/pypy/module/signal/stmactionflag.py
b/pypy/module/signal/stmactionflag.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/signal/stmactionflag.py
@@ -0,0 +1,28 @@
+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
diff --git a/rpython/rlib/rsignal.py b/rpython/rlib/rsignal.py
--- a/rpython/rlib/rsignal.py
+++ b/rpython/rlib/rsignal.py
@@ -45,7 +45,8 @@
'pypysig_ignore', 'pypysig_setflag',
'pypysig_reinstall',
'pypysig_set_wakeup_fd',
- 'pypysig_getaddr_occurred'],
+ 'pypysig_getaddr_occurred',
+ 'pypysig_get_occurred', 'pypysig_set_occurred'],
)
class CConfig:
@@ -93,6 +94,12 @@
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)
diff --git a/rpython/translator/c/src/signals.h
b/rpython/translator/c/src/signals.h
--- a/rpython/translator/c/src/signals.h
+++ b/rpython/translator/c/src/signals.h
@@ -26,4 +26,7 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit