[pypy-commit] pypy stm: Start the rstm module.
arigo
noreply at buildbot.pypy.org
Tue Sep 27 15:24:06 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r47624:8c1978605a34
Date: 2011-09-27 14:46 +0200
http://bitbucket.org/pypy/pypy/changeset/8c1978605a34/
Log: Start the rstm module.
diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -384,6 +384,13 @@
'direct_ptradd': LLOp(canfold=True),
'cast_opaque_ptr': LLOp(sideeffects=False),
+ # __________ Software Transactional Memory __________
+ # (Note that these operations could also be decomposed into individual
+ # direct_calls and maybe several casts, but it looks less heavy-weight
+ # to keep them as operations until the genc stage)
+
+ 'stm_getfield': LLOp(sideeffects=False, canrun=True),
+
# __________ address operations __________
'boehm_malloc': LLOp(),
diff --git a/pypy/translator/stm/rstm.py b/pypy/translator/stm/rstm.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/stm/rstm.py
@@ -0,0 +1,9 @@
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.translator.stm import _rffi_stm
+
+
+def stm_getfield(structptr, fieldname):
+ p = lltype.direct_fieldptr(structptr, fieldname)
+ p = rffi.cast(rffi.VOIDPP, p)
+ res = _rffi_stm.stm_read_word(p)
+ return rffi.cast(lltype.Signed, res)
diff --git a/pypy/translator/stm/test/test_basic.py b/pypy/translator/stm/test/test_basic.py
deleted file mode 100644
--- a/pypy/translator/stm/test/test_basic.py
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/pypy/translator/stm/test/test_rffi_stm.py b/pypy/translator/stm/test/test_rffi_stm.py
--- a/pypy/translator/stm/test/test_rffi_stm.py
+++ b/pypy/translator/stm/test/test_rffi_stm.py
@@ -42,6 +42,7 @@
assert rffi.cast(lltype.Signed, stm_read_word(p)) == -611
stm_write_word(p, rffi.cast(rffi.VOIDP, 42 * a.y))
assert rffi.cast(lltype.Signed, stm_read_word(p)) == 42 * a.y
+ assert a.x == -611 # xxx still the old value when reading non-transact.
if a.y < 10:
a.y += 1 # non-transactionally
abort_and_retry()
diff --git a/pypy/translator/stm/test/test_rstm.py b/pypy/translator/stm/test/test_rstm.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/stm/test/test_rstm.py
@@ -0,0 +1,28 @@
+from pypy.translator.stm._rffi_stm import *
+from pypy.translator.stm.rstm import *
+from pypy.rpython.annlowlevel import llhelper
+
+
+def test_stm_getfield():
+ A = lltype.Struct('A', ('x', lltype.Signed), ('y', lltype.Signed))
+ a = lltype.malloc(A, immortal=True, flavor='raw')
+ a.x = -611
+ a.y = 0
+ def callback1(x):
+ assert a.x == -611
+ assert stm_getfield(a, 'x') == -611
+ p = lltype.direct_fieldptr(a, 'x')
+ p = rffi.cast(rffi.VOIDPP, p)
+ stm_write_word(p, rffi.cast(rffi.VOIDP, 42 * a.y))
+ assert stm_getfield(a, 'x') == 42 * a.y
+ assert a.x == -611 # xxx still the old value when reading non-transact.
+ if a.y < 10:
+ a.y += 1 # non-transactionally
+ abort_and_retry()
+ else:
+ return lltype.nullptr(rffi.VOIDP.TO)
+ descriptor_init()
+ perform_transaction(llhelper(CALLBACK, callback1),
+ lltype.nullptr(rffi.VOIDP.TO))
+ descriptor_done()
+ assert a.x == 420
More information about the pypy-commit
mailing list