[pypy-commit] pypy stm: (bivab, arigo)

arigo noreply at buildbot.pypy.org
Thu Jan 19 18:21:21 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51495:5d6f1589889c
Date: 2012-01-19 18:19 +0100
http://bitbucket.org/pypy/pypy/changeset/5d6f1589889c/

Log:	(bivab, arigo) Translation fixes.

diff --git a/pypy/module/transaction/__init__.py b/pypy/module/transaction/__init__.py
--- a/pypy/module/transaction/__init__.py
+++ b/pypy/module/transaction/__init__.py
@@ -9,10 +9,10 @@
         'set_num_threads': 'interp_transaction.set_num_threads',
         'add': 'interp_transaction.add',
         'run': 'interp_transaction.run',
-        'TransactionError': 'interp_transaction.state.w_error',
     }
 
     appleveldefs = {
+        'TransactionError': 'app_transaction.TransactionError',
     }
 
     def startup(self, space):
diff --git a/pypy/module/transaction/interp_transaction.py b/pypy/module/transaction/interp_transaction.py
--- a/pypy/module/transaction/interp_transaction.py
+++ b/pypy/module/transaction/interp_transaction.py
@@ -13,15 +13,20 @@
         self.__dict__.clear()
         self.running = False
         self.num_threads = NUM_THREADS_DEFAULT
+        self.pending = []
+        self.pending_lists = {0: self.pending}
+        self.ll_lock = threadintf.null_ll_lock
+        self.ll_no_tasks_pending_lock = threadintf.null_ll_lock
+        self.ll_unfinished_lock = threadintf.null_ll_lock
 
     def startup(self, space):
         self.space = space
-        self.pending = []
+        w_module = space.getbuiltinmodule('transaction')
+        self.w_error = space.getattr(w_module, space.wrap('TransactionError'))
+        #
         self.ll_lock = threadintf.allocate_lock()
         self.ll_no_tasks_pending_lock = threadintf.allocate_lock()
         self.ll_unfinished_lock = threadintf.allocate_lock()
-        self.w_error = space.new_exception_class(
-            "transaction.TransactionError")
         self.lock_unfinished()
         self.main_thread_id = threadintf.thread_id()
         self.pending_lists = {self.main_thread_id: self.pending}
@@ -33,7 +38,7 @@
                                  space.wrap("cannot change the number of "
                                             "threads when transaction.run() "
                                             "is active"))
-        self.num_threads = num_threads
+        self.num_threads = num
 
     def lock(self):
         # XXX think about the interaction between locks and the GC
diff --git a/pypy/module/transaction/test/test_transaction.py b/pypy/module/transaction/test/test_transaction.py
--- a/pypy/module/transaction/test/test_transaction.py
+++ b/pypy/module/transaction/test/test_transaction.py
@@ -6,6 +6,10 @@
     def setup_class(cls):
         cls.space = gettestobjspace(usemodules=['transaction'])
 
+    def test_set_num_threads(self):
+        import transaction
+        transaction.set_num_threads(4)
+
     def test_simple(self):
         import transaction
         lst = []
diff --git a/pypy/module/transaction/threadintf.py b/pypy/module/transaction/threadintf.py
--- a/pypy/module/transaction/threadintf.py
+++ b/pypy/module/transaction/threadintf.py
@@ -1,22 +1,36 @@
 import thread
+from pypy.module.thread import ll_thread
+from pypy.rlib.objectmodel import we_are_translated
 
 
+null_ll_lock = ll_thread.null_ll_lock
+
 def allocate_lock():
-    "NOT_RPYTHON"
-    return thread.allocate_lock()
+    if we_are_translated():
+        return ll_thread.allocate_ll_lock()
+    else:
+        return thread.allocate_lock()
 
 def acquire(lock, wait):
-    "NOT_RPYTHON"
-    return lock.acquire(wait)
+    if we_are_translated():
+        return ll_thread.acquire_NOAUTO(lock, wait)
+    else:
+        return lock.acquire(wait)
 
 def release(lock):
-    "NOT_RPYTHON"
-    lock.release()
+    if we_are_translated():
+        ll_thread.release_NOAUTO(lock)
+    else:
+        lock.release()
 
 def start_new_thread(callback, args):
-    "NOT_RPYTHON"
-    thread.start_new_thread(callback, args)
+    if we_are_translated():
+        ll_thread.start_new_thread(callback, args)
+    else:
+        thread.start_new_thread(callback, args)
 
 def thread_id():
-    "NOT_RPYTHON"
-    return thread.get_ident()
+    if we_are_translated():
+        return ll_thread.get_ident()
+    else:
+        return thread.get_ident()


More information about the pypy-commit mailing list