[pypy-commit] pypy stm-gc: Fix local.

arigo noreply at buildbot.pypy.org
Mon Apr 23 10:28:07 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54648:c76e8c2a1758
Date: 2012-04-23 10:23 +0200
http://bitbucket.org/pypy/pypy/changeset/c76e8c2a1758/

Log:	Fix local.

diff --git a/pypy/module/transaction/interp_local.py b/pypy/module/transaction/interp_local.py
--- a/pypy/module/transaction/interp_local.py
+++ b/pypy/module/transaction/interp_local.py
@@ -1,7 +1,7 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import (TypeDef, interp2app, GetSetProperty,
     descr_get_dict)
-#from pypy.module.transaction.interp_transaction import state
+from pypy.module.transaction.interp_transaction import getstate
 
 
 class W_Local(Wrappable):
@@ -18,27 +18,29 @@
     """
 
     def __init__(self, space):
+        self.state = getstate(space)
         self.dicts = []
-        self._update_dicts(space)
+        self._update_dicts()
         # unless we call transaction.set_num_threads() afterwards, this
         # 'local' object is now initialized with the correct number of
         # dictionaries, to avoid conflicts later if _update_dicts() is
         # called in a transaction.
 
-    def _update_dicts(self, space):
+    def _update_dicts(self):
+        state = self.state
         new = state.get_total_number_of_threads() - len(self.dicts)
         if new <= 0:
             return
         # update the list without appending to it (to keep it non-resizable)
-        self.dicts = self.dicts + [space.newdict(instance=True)
+        self.dicts = self.dicts + [state.space.newdict(instance=True)
                                    for i in range(new)]
 
     def getdict(self, space):
-        n = state.get_thread_number()
+        n = self.state.get_thread_number()
         try:
             return self.dicts[n]
         except IndexError:
-            self._update_dicts(space)
+            self._update_dicts()
             assert n < len(self.dicts)
             return self.dicts[n]
 
diff --git a/pypy/rlib/test/test_rstm.py b/pypy/rlib/test/test_rstm.py
--- a/pypy/rlib/test/test_rstm.py
+++ b/pypy/rlib/test/test_rstm.py
@@ -6,16 +6,14 @@
 
 class FakeStmOperations:
     _in_transaction = 0
+    _thread_id = 0
     _mapping = {}
 
     def in_transaction(self):
         return self._in_transaction
 
     def thread_id(self):
-        if self._in_transaction:
-            return -12345    # random number
-        else:
-            return 0
+        return self._thread_id
 
     def _add(self, transactionptr):
         r = random.random()
@@ -25,9 +23,12 @@
     def run_all_transactions(self, initial_transaction_ptr, num_threads=4):
         self._pending = {}
         self._add(initial_transaction_ptr)
+        thread_ids = [-10000 - 123 * i for i in range(num_threads)]  # random
         self._in_transaction = True
         try:
             while self._pending:
+                self._thread_id = thread_ids.pop(0)
+                thread_ids.append(self._thread_id)
                 r, transactionptr = self._pending.popitem()
                 transaction = self.cast_voidp_to_transaction(transactionptr)
                 transaction._next_transaction = None
@@ -38,6 +39,7 @@
                     next = next._next_transaction
         finally:
             self._in_transaction = False
+            self._thread_id = 0
             del self._pending
 
     def cast_transaction_to_voidp(self, transaction):


More information about the pypy-commit mailing list