Author: Armin Rigo <[email protected]>
Branch: stm-thread-2
Changeset: r61322:b692761b4013
Date: 2013-02-16 15:58 +0100
http://bitbucket.org/pypy/pypy/changeset/b692761b4013/
Log: Argh. Disable this cache if we are running with stm.
diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py
--- a/pypy/module/thread/os_local.py
+++ b/pypy/module/thread/os_local.py
@@ -19,6 +19,7 @@
@jit.dont_look_inside
def __init__(self, space, initargs):
+ self.space = space
self.initargs = initargs
self.dicts = {} # mapping ExecutionContexts to the wraped dict
# The app-level __init__() will be called by the general
@@ -31,11 +32,16 @@
self.dicts[ec] = w_dict
self._register_in_ec(ec)
# cache the last seen dict, works because we are protected by the GIL
- self.last_dict = w_dict
- self.last_ec = ec
+ if self.can_cache():
+ self.last_dict = w_dict
+ self.last_ec = ec
+
+ def can_cache(self):
+ # can't cache with STM! The cache causes conflicts
+ return not self.space.config.translation.stm
def _register_in_ec(self, ec):
- if not ec.space.config.translation.rweakref:
+ if not self.space.config.translation.rweakref:
return # without weakrefs, works but 'dicts' is never cleared
if ec._thread_local_objs is None:
ec._thread_local_objs = WRefShrinkList()
@@ -44,7 +50,7 @@
@jit.dont_look_inside
def create_new_dict(self, ec):
# create a new dict for this thread
- space = ec.space
+ space = self.space
w_dict = space.newdict(instance=True)
self.dicts[ec] = w_dict
# call __init__
@@ -63,14 +69,15 @@
def getdict(self, space):
ec = space.getexecutioncontext()
- if ec is self.last_ec:
+ if self.can_cache() and ec is self.last_ec:
return self.last_dict
try:
w_dict = self.dicts[ec]
except KeyError:
w_dict = self.create_new_dict(ec)
- self.last_ec = ec
- self.last_dict = w_dict
+ if self.can_cache():
+ self.last_ec = ec
+ self.last_dict = w_dict
return w_dict
def descr_local__new__(space, w_subtype, __args__):
diff --git a/pypy/module/thread/test/test_local.py
b/pypy/module/thread/test/test_local.py
--- a/pypy/module/thread/test/test_local.py
+++ b/pypy/module/thread/test/test_local.py
@@ -128,6 +128,7 @@
class config:
class translation:
rweakref = True
+ stm = False
class FakeEC:
def __init__(self, space):
@@ -158,4 +159,3 @@
l.dicts = "nope"
assert l.getdict(space) is d1
l.dicts = dicts
-
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit