[pypy-commit] pypy ec-threadlocal: Copy a test from rstm. Add another (failing) translation test.
arigo
noreply at buildbot.pypy.org
Sun Jun 22 17:16:33 CEST 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: ec-threadlocal
Changeset: r72133:a34d95b12b36
Date: 2014-06-22 17:15 +0200
http://bitbucket.org/pypy/pypy/changeset/a34d95b12b36/
Log: Copy a test from rstm. Add another (failing) translation test.
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -304,6 +304,7 @@
return getattr(self.local, 'value', None)
@specialize.arg(0)
+ @jit.dont_look_inside
def set(self, value):
assert isinstance(value, self.Cls) or value is None
if we_are_translated():
diff --git a/rpython/rlib/test/test_rthread.py b/rpython/rlib/test/test_rthread.py
--- a/rpython/rlib/test/test_rthread.py
+++ b/rpython/rlib/test/test_rthread.py
@@ -1,4 +1,4 @@
-import gc
+import gc, time
from rpython.rlib.rthread import *
from rpython.translator.c.test.test_boehm import AbstractGCTestClass
from rpython.rtyper.lltypesystem import lltype, rffi
@@ -29,6 +29,23 @@
else:
py.test.fail("Did not raise")
+def test_tlref_untranslated():
+ class FooBar(object):
+ pass
+ t = ThreadLocalReference(FooBar)
+ results = []
+ def subthread():
+ x = FooBar()
+ results.append(t.get() is None)
+ t.set(x)
+ results.append(t.get() is x)
+ time.sleep(0.2)
+ results.append(t.get() is x)
+ for i in range(5):
+ start_new_thread(subthread, ())
+ time.sleep(0.5)
+ assert results == [True] * 15
+
class AbstractThreadTests(AbstractGCTestClass):
use_threads = True
@@ -198,6 +215,19 @@
res = fn()
assert res >= 0.95
+ def test_tlref(self):
+ class FooBar(object):
+ pass
+ t = ThreadLocalReference(FooBar)
+ def f():
+ x1 = FooBar()
+ t.set(x1)
+ assert t.get() is x1
+ return 42
+ fn = self.getcompiled(f, [])
+ res = fn()
+ assert res == 42
+
#class TestRunDirectly(AbstractThreadTests):
# def getcompiled(self, f, argtypes):
# return f
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
@@ -541,6 +541,9 @@
'getslice': LLOp(canraise=(Exception,)),
'check_and_clear_exc': LLOp(),
+ 'threadlocalref_get': LLOp(sideeffects=False),
+ 'threadlocalref_set': LLOp(),
+
# __________ debugging __________
'debug_view': LLOp(),
'debug_print': LLOp(canrun=True),
More information about the pypy-commit
mailing list