[pypy-commit] pypy stmgc-c7: add is_atomic()
Raemi
noreply at buildbot.pypy.org
Tue Jul 22 13:41:15 CEST 2014
Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: stmgc-c7
Changeset: r72479:7e8ed49b6d70
Date: 2014-07-22 13:40 +0200
http://bitbucket.org/pypy/pypy/changeset/7e8ed49b6d70/
Log: add is_atomic()
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -42,6 +42,7 @@
'reset_longest_abort_info':'interp_atomic.reset_longest_abort_info',
'getsegmentlimit': 'interp_atomic.getsegmentlimit',
'hint_commit_soon': 'interp_atomic.hint_commit_soon',
+ 'is_atomic': 'interp_atomic.is_atomic',
'error': 'space.fromcache(pypy.module.thread.error.Cache).w_error',
}
def activate(self, space):
diff --git a/pypy/module/__pypy__/interp_atomic.py b/pypy/module/__pypy__/interp_atomic.py
--- a/pypy/module/__pypy__/interp_atomic.py
+++ b/pypy/module/__pypy__/interp_atomic.py
@@ -60,6 +60,15 @@
else:
return space.wrap(1)
+def is_atomic(space):
+ if space.config.translation.stm:
+ from rpython.rlib.rstm import is_atomic
+ return space.wrap(is_atomic())
+ else:
+ giltl = space.threadlocals
+ return space.wrap(giltl.is_atomic)
+
+
@unwrap_spec(mintime=float)
def longest_abort_info(space, mintime=0.0):
if space.config.translation.stm:
diff --git a/pypy/module/__pypy__/test/test_atomic.py b/pypy/module/__pypy__/test/test_atomic.py
--- a/pypy/module/__pypy__/test/test_atomic.py
+++ b/pypy/module/__pypy__/test/test_atomic.py
@@ -1,11 +1,10 @@
from __future__ import with_statement
from pypy.module.thread.test.support import GenericTestThread
-from pypy.module.__pypy__.interp_atomic import bdecode
from rpython.rtyper.lltypesystem import rffi
def test_bdecode(space):
-
+ from pypy.module.__pypy__.interp_atomic import bdecode
def bdec(s, expected):
p = rffi.str2charp(s)
w_obj, q = bdecode(space, p)
@@ -27,7 +26,7 @@
from __pypy__ import thread
for atomic in thread.atomic, thread.exclusive_atomic:
with atomic:
- pass
+ assert thread.is_atomic()
try:
with atomic:
raise ValueError
@@ -38,22 +37,28 @@
from __pypy__ import thread
with thread.atomic:
with thread.atomic:
- pass
+ assert thread.is_atomic()
+ assert thread.is_atomic()
+ assert not thread.is_atomic()
def test_nest_composable_below_exclusive(self):
from __pypy__ import thread
with thread.exclusive_atomic:
with thread.atomic:
with thread.atomic:
- pass
+ assert thread.is_atomic()
+ assert thread.is_atomic()
+ assert thread.is_atomic()
+ assert not thread.is_atomic()
def test_nest_exclusive_fails(self):
from __pypy__ import thread
try:
with thread.exclusive_atomic:
with thread.exclusive_atomic:
- pass
+ assert thread.is_atomic()
except thread.error, e:
+ assert not thread.is_atomic()
assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
def test_nest_exclusive_fails2(self):
@@ -61,6 +66,8 @@
try:
with thread.atomic:
with thread.exclusive_atomic:
- pass
+ assert thread.is_atomic()
+ assert thread.is_atomic()
except thread.error, e:
+ assert not thread.is_atomic()
assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
More information about the pypy-commit
mailing list