[pypy-commit] pypy stm: (antocuni, arigo)
arigo
noreply at buildbot.pypy.org
Mon Jan 16 18:29:45 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51360:dbadc138e9b5
Date: 2012-01-16 18:29 +0100
http://bitbucket.org/pypy/pypy/changeset/dbadc138e9b5/
Log: (antocuni, arigo)
Add an integration test to test_rstm.py: really call
rstm.perform_transaction() in a C-compiled test.
diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -1,5 +1,5 @@
from pypy.rlib.objectmodel import specialize, we_are_translated, keepalive_until_here
-from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.rpython.lltypesystem import rffi, lltype, rclass
from pypy.rpython.annlowlevel import (cast_base_ptr_to_instance,
cast_instance_to_base_ptr,
llhelper)
diff --git a/pypy/rlib/test/test_rstm.py b/pypy/rlib/test/test_rstm.py
--- a/pypy/rlib/test/test_rstm.py
+++ b/pypy/rlib/test/test_rstm.py
@@ -2,14 +2,18 @@
from pypy.rlib import rstm
from pypy.translator.stm.test.support import CompiledSTMTests
+
+class Arg(object):
+ _alloc_nonmovable_ = True
+
+def setx(arg):
+ debug_print(arg.x)
+ arg.x = 42
+
+
def test_stm_perform_transaction():
- class Arg(object):
- _alloc_nonmovable_ = True
-
- def setx(arg):
- arg.x = 42
-
arg = Arg()
+ arg.x = 202
rstm.descriptor_init()
rstm.perform_transaction(setx, Arg, arg)
rstm.descriptor_done()
@@ -29,3 +33,12 @@
dataout, dataerr = cbuilder.cmdexec('', err=True)
assert dataout == ''
assert '102' in dataerr.splitlines()
+
+ def test_perform_transaction(self):
+ def f(argv):
+ test_stm_perform_transaction()
+ return 0
+ t, cbuilder = self.compile(f)
+ dataout, dataerr = cbuilder.cmdexec('', err=True)
+ assert dataout == ''
+ assert '202' in dataerr.splitlines()
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -226,9 +226,7 @@
yield '\tRPyConvertExceptionToCPython();'
yield '\treturn NULL;'
yield '}'
- if self.exception_policy == "stm":
- xxxx
- yield 'STM_MAKE_INEVITABLE();'
+ assert self.exception_policy != "stm", "old code"
retval = self.expr(block.inputargs[0])
if self.exception_policy != "exc_helper":
yield 'RPY_DEBUG_RETURN();'
@@ -609,6 +607,7 @@
OP_STM_SETARRAYITEM = _OP_STM
OP_STM_GETINTERIORFIELD = _OP_STM
OP_STM_SETINTERIORFIELD = _OP_STM
+ OP_STM_BECOME_INEVITABLE = _OP_STM
def OP_PTR_NONZERO(self, op):
diff --git a/pypy/translator/stm/funcgen.py b/pypy/translator/stm/funcgen.py
--- a/pypy/translator/stm/funcgen.py
+++ b/pypy/translator/stm/funcgen.py
@@ -118,49 +118,7 @@
return _stm_generic_set(funcgen, op, expr, T)
-def stm_begin_transaction(funcgen, op):
- return 'STM_begin_transaction();'
-
-def stm_commit_transaction(funcgen, op):
- return 'stm_commit_transaction();'
-
-def stm_begin_inevitable_transaction(funcgen, op):
- return 'stm_begin_inevitable_transaction();'
-
-def stm_declare_variable(funcgen, op):
- # this operation occurs only once at the start of a function if
- # it uses stm_transaction_boundary
- assert funcgen.exception_policy is None
- funcgen.exception_policy = 'stm'
- return 'STM_DECLARE_VARIABLE();'
-
-def stm_transaction_boundary(funcgen, op):
- assert funcgen.exception_policy == 'stm'
- # make code looking like this:
- #
- # stm_commit_transaction();
- # {
- # volatile long tmp_123 = l_123;
- # setjmp(jmpbuf);
- # l_123 = tmp_123;
- # }
- # stm_begin_transaction(&jmpbuf);
- #
- lines = ['\tsetjmp(jmpbuf);']
- TMPVAR = 'tmp_%s'
- for v in op.args:
- tmpname = TMPVAR % v.name
- cdeclname = cdecl(funcgen.lltypename(v), 'volatile ' + tmpname)
- realname = funcgen.expr(v)
- lines.insert(0, '\t%s = %s;' % (cdeclname, realname))
- lines.append('\t%s = %s;' % (realname, tmpname))
- lines.insert(0, '{')
- lines.insert(0, 'stm_commit_transaction();')
- lines.append('}')
- lines.append('stm_begin_transaction(&jmpbuf);')
- return '\n'.join(lines)
-
-def stm_try_inevitable(funcgen, op):
+def stm_become_inevitable(funcgen, op):
info = op.args[0].value
string_literal = c_string_constant(info)
return 'stm_try_inevitable(STM_EXPLAIN1(%s));' % (string_literal,)
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -775,6 +775,8 @@
by another thread. We set the lowest bit in global_timestamp
to 1. */
struct tx_descriptor *d = thread_descriptor;
+ if (!d)
+ return;
#ifdef RPY_STM_ASSERT
PYPY_DEBUG_START("stm-inevitable");
More information about the pypy-commit
mailing list