[pypy-commit] pypy stm: Use thread_id() from stm instead of the one from threads.

arigo noreply at buildbot.pypy.org
Mon Jan 23 17:30:26 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51691:db48523657f2
Date: 2012-01-23 16:21 +0100
http://bitbucket.org/pypy/pypy/changeset/db48523657f2/

Log:	Use thread_id() from stm instead of the one from threads.

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
@@ -7,6 +7,8 @@
 
 NUM_THREADS_DEFAULT = 4     # by default
 
+MAIN_THREAD_ID = 0
+
 
 class State(object):
 
@@ -19,7 +21,6 @@
         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
-        self.main_thread_id = 0
         self.w_error = None
 
     def startup(self, space):
@@ -31,8 +32,7 @@
         self.ll_no_tasks_pending_lock = threadintf.allocate_lock()
         self.ll_unfinished_lock = threadintf.allocate_lock()
         self.lock_unfinished()
-        self.main_thread_id = threadintf.thread_id()
-        self.pending_lists = {self.main_thread_id: self.pending}
+        self.pending_lists = {MAIN_THREAD_ID: self.pending}
 
     def set_num_threads(self, num):
         if self.running:
@@ -88,7 +88,7 @@
         self.args = args
 
     def register(self):
-        id = threadintf.thread_id()
+        id = rstm.thread_id()
         state.pending_lists[id].append(self)
 
     def run(self):
@@ -112,7 +112,7 @@
     Pending(w_callback, __args__).register()
 
 
-def add_list(new_pending_list):
+def _add_list(new_pending_list):
     if new_pending_list.is_empty():
         return
     was_empty = state.pending.is_empty()
@@ -123,10 +123,11 @@
 
 def _run_thread():
     state.lock()
+    rstm.descriptor_init()
     my_pending_list = Fifo()
-    my_thread_id = threadintf.thread_id()
+    my_thread_id = rstm.thread_id()
+    assert my_thread_id not in state.pending_lists
     state.pending_lists[my_thread_id] = my_pending_list
-    rstm.descriptor_init()
     #
     while True:
         if state.pending.is_empty():
@@ -151,7 +152,7 @@
             state.unlock()
             pending.run()
             state.lock()
-            add_list(my_pending_list)
+            _add_list(my_pending_list)
     #
     rstm.descriptor_done()
     del state.pending_lists[my_thread_id]
@@ -180,7 +181,7 @@
     #
     assert state.num_waiting_threads == 0
     assert state.pending.is_empty()
-    assert state.pending_lists.keys() == [state.main_thread_id]
+    assert state.pending_lists.keys() == [MAIN_THREAD_ID]
     assert not state.is_locked_no_tasks_pending()
     state.running = False
     #
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
@@ -28,9 +28,3 @@
         ll_thread.start_new_thread(callback, args)
     else:
         thread.start_new_thread(callback, args)
-
-def thread_id():
-    if we_are_translated():
-        return ll_thread.get_ident()
-    else:
-        return thread.get_ident()
diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -55,3 +55,6 @@
 
 def debug_get_state():
     return _rffi_stm.stm_debug_get_state()
+
+def thread_id():
+    return _rffi_stm.stm_thread_id()


More information about the pypy-commit mailing list