Commits

Armin Rigo committed beecf13

Don't use a dict at all to store the executioncontext.

Comments (0)

Files changed (3)

pypy/module/sys/currentframes.py

     w_result = space.newdict()
     w_fake_frame = app.wget(space, "fake_frame")
     w_fake_code  = app.wget(space, "fake_code")
-    ecs = space.threadlocals.getallvalues()
+    try:
+        ecs = space.threadlocals.getallvalues()
+    except ValueError:
+        raise OperationError(space.w_RuntimeError,
+                             space.wrap("sys._current_frames() not supported"
+                                        " on this configuration"))
     for thread_ident, ec in ecs.items():
         vref = ec.topframeref
         frames = []

pypy/module/thread/stm.py

 
 class STMThreadLocals(OSThreadLocals):
 
+    use_dict = False
+
     def initialize(self, space):
         """NOT_RPYTHON: set up a mechanism to send to the C code the value
         set by space.actionflag.setcheckinterval()."""
         space.actionflag.setcheckinterval_callback = setcheckinterval_callback
         self.threads_running = False
 
-    def clear_cache(self):
-        ec_cache.set(None)
+    def getvalue(self):
+        return ec_cache.get()
 
-    def getvalue(self):
-        value = ec_cache.get()
-        if value is None:
-            ident = rthread.get_ident()
-            value = self._valuedict.get(ident, None)
-            ec_cache.set(value)
-        return value
+    def setvalue(self, value):
+        ec_cache.set(value)
+
+    def getallvalues(self):
+        raise ValueError
 
     def setup_threads(self, space):
         self.threads_running = True

pypy/module/thread/threadlocals.py

     a thread finishes.  This works as long as the thread was started by
     os_thread.bootstrap()."""
 
+    use_dict = True
+
     def __init__(self):
-        self._valuedict = {}   # {thread_ident: ExecutionContext()}
+        if self.use_dict:
+            self._valuedict = {}   # {thread_ident: ExecutionContext()}
         self._cleanup_()
 
     def _cleanup_(self):
-        self._valuedict.clear()
+        if self.use_dict:
+            self._valuedict.clear()
+            self.clear_cache()
         self._mainthreadident = 0
-        self.clear_cache()
 
     def clear_cache(self):
         # Cache function: fast minicaching for the common case.  Relies
         return result
 
     def setvalue(self, value):
+        # Overridden in stm.py.
         ident = rthread.get_ident()
         if value is not None:
             if len(self._valuedict) == 0:
         ec._signals_enabled = new
 
     def getallvalues(self):
+        # Overridden in stm.py.
         return self._valuedict
 
     def leave_thread(self, space):