Commits

Armin Rigo committed b692761

Argh. Disable this cache if we are running with stm.

  • Participants
  • Parent commits effc55e
  • Branches stm-thread-2

Comments (0)

Files changed (2)

pypy/module/thread/os_local.py

 
     @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
         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()
     @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__
 
     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__):

pypy/module/thread/test/test_local.py

         class config:
             class translation:
                 rweakref = True
+                stm = False
 
     class FakeEC:
         def __init__(self, space):
     l.dicts = "nope"
     assert l.getdict(space) is d1
     l.dicts = dicts
-