Author: Armin Rigo <[email protected]>
Branch: stmgc-c4
Changeset: r67107:4c16a18b6a43
Date: 2013-09-26 08:56 +0200
http://bitbucket.org/pypy/pypy/changeset/4c16a18b6a43/
Log: Try to revert module/signal and use a 'stm_dont_track_raw_accesses'
flag on the result of pypysig_getaddr_occurred() instead.
diff --git a/pypy/interpreter/executioncontext.py
b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -345,7 +345,7 @@
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:
@@ -378,7 +378,7 @@
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()
@@ -415,6 +415,9 @@
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
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
@@ -46,10 +46,5 @@
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
diff --git a/pypy/module/signal/actionflag.py b/pypy/module/signal/actionflag.py
deleted file mode 100644
--- a/pypy/module/signal/actionflag.py
+++ /dev/null
@@ -1,33 +0,0 @@
-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,7 +4,8 @@
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
@@ -17,6 +18,40 @@
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."""
@@ -170,7 +205,7 @@
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)
@@ -203,7 +238,7 @@
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))
diff --git a/pypy/module/signal/stmactionflag.py
b/pypy/module/signal/stmactionflag.py
deleted file mode 100644
--- a/pypy/module/signal/stmactionflag.py
+++ /dev/null
@@ -1,43 +0,0 @@
-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
diff --git a/rpython/rlib/rsignal.py b/rpython/rlib/rsignal.py
--- a/rpython/rlib/rsignal.py
+++ b/rpython/rlib/rsignal.py
@@ -86,20 +86,20 @@
# 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)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit