[pypy-commit] pypy stmgc-c7: Add _stm.count(), which returns a new integer every time it is called.
arigo
noreply at buildbot.pypy.org
Mon Nov 10 16:15:15 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r74427:3dc9224b99dc
Date: 2014-11-10 16:13 +0100
http://bitbucket.org/pypy/pypy/changeset/3dc9224b99dc/
Log: Add _stm.count(), which returns a new integer every time it is
called.
diff --git a/pypy/module/_stm/__init__.py b/pypy/module/_stm/__init__.py
--- a/pypy/module/_stm/__init__.py
+++ b/pypy/module/_stm/__init__.py
@@ -8,4 +8,5 @@
interpleveldefs = {
'local': 'local.STMLocal',
+ 'count': 'count.count',
}
diff --git a/pypy/module/_stm/count.py b/pypy/module/_stm/count.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_stm/count.py
@@ -0,0 +1,12 @@
+"""
+_stm.count()
+"""
+
+from rpython.rlib import rstm
+
+
+def count(space):
+ """Return a new integer every time it is called,
+without generating conflicts."""
+ count = rstm.stm_count()
+ return space.wrap(count)
diff --git a/pypy/module/_stm/test/test_count.py b/pypy/module/_stm/test/test_count.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_stm/test/test_count.py
@@ -0,0 +1,10 @@
+
+
+class AppTestCount:
+ spaceconfig = dict(usemodules=['_stm'])
+
+ def test_count(self):
+ import _stm
+ x = _stm.count()
+ y = _stm.count()
+ assert y == x + 1
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -156,7 +156,7 @@
def pop_marker():
llop.stm_pop_marker(lltype.Void)
-def stm_count(): # for tests
+def stm_count():
return llop.stm_count(lltype.Signed)
# ____________________________________________________________
diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -458,7 +458,7 @@
'stm_expand_marker': LLOp(),
'stm_setup_expand_marker_for_pypy': LLOp(),
- 'stm_count': LLOp(),
+ 'stm_count': LLOp(canrun=True),
'stm_really_force_cast_ptr': LLOp(),
# __________ address operations __________
diff --git a/rpython/rtyper/lltypesystem/opimpl.py b/rpython/rtyper/lltypesystem/opimpl.py
--- a/rpython/rtyper/lltypesystem/opimpl.py
+++ b/rpython/rtyper/lltypesystem/opimpl.py
@@ -724,6 +724,13 @@
def op_stm_hint_commit_soon():
pass
+def op_stm_count():
+ global _stm_counter
+ x = _stm_counter
+ _stm_counter = x + 1
+ return x
+_stm_counter = 0
+
# ____________________________________________________________
diff --git a/rpython/translator/stm/src_stm/stmgcintf.c b/rpython/translator/stm/src_stm/stmgcintf.c
--- a/rpython/translator/stm/src_stm/stmgcintf.c
+++ b/rpython/translator/stm/src_stm/stmgcintf.c
@@ -224,7 +224,6 @@
long _pypy_stm_count(void)
{
- /* for tests */
static long value = 0;
- return value++;
+ return __sync_fetch_and_add(&value, 1);
}
More information about the pypy-commit
mailing list