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

arigo noreply at buildbot.pypy.org
Sat Feb 11 16:26:37 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r52372:25a1c74bdc71
Date: 2012-02-11 12:47 +0100
http://bitbucket.org/pypy/pypy/changeset/25a1c74bdc71/

Log:	Fix fix fix.

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
@@ -77,7 +77,7 @@
         self.threadobjs[id] = value
 
     def getmainthreadvalue(self):
-        return self.threadobjs[self.main_thread_id]
+        return self.threadobjs.get(self.main_thread_id, None)
 
     def getallvalues(self):
         return self.threadobjs
@@ -267,6 +267,7 @@
             state.w_error,
             space.wrap("recursive invocation of transaction.run()"))
     state.startup_run()
+    assert state.main_thread_id == rstm.thread_id()
     assert not state.is_locked_no_tasks_pending()
     if state.pending.is_empty():
         return
@@ -291,10 +292,8 @@
     #
     assert state.num_waiting_threads == 0
     assert state.pending.is_empty()
-    assert state.threadobjs.keys() == [MAIN_THREAD_ID]
+    assert state.threadobjs.keys() == [state.main_thread_id]
     assert not state.is_locked_no_tasks_pending()
-    assert state.threadobjects == []
-    state.threadobjects = None
     state.running = False
     #
     # now re-raise the exception that we got in a transaction
diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -1,5 +1,7 @@
 import thread
-from pypy.rlib.objectmodel import specialize, we_are_translated, keepalive_until_here
+from pypy.rlib.objectmodel import specialize, we_are_translated
+from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib.debug import ll_assert
 from pypy.rpython.lltypesystem import rffi, lltype, rclass
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.annlowlevel import (cast_base_ptr_to_instance,
@@ -20,7 +22,7 @@
             arg = lltype.TLS.stm_callback_arg
         try:
             res = func(arg, retry_counter)
-            assert res is None
+            ll_assert(res is None, "stm_callback should return None")
         finally:
             llop.stm_commit_transaction(lltype.Void)
         return lltype.nullptr(rffi.VOIDP.TO)
@@ -28,8 +30,10 @@
 
 @specialize.arg(0, 1)
 def perform_transaction(func, argcls, arg):
-    assert isinstance(arg, argcls)
-    assert argcls._alloc_nonmovable_
+    ll_assert(arg is None or isinstance(arg, argcls),
+              "perform_transaction: wrong class")
+    ll_assert(argcls._alloc_nonmovable_,
+              "perform_transaction: XXX")    # XXX kill me
     if we_are_translated():
         llarg = cast_instance_to_base_ptr(arg)
         llarg = rffi.cast(rffi.VOIDP, llarg)
diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -399,11 +399,11 @@
     'stm_getarrayitem':       LLOp(sideeffects=False, canrun=True),
     'stm_getinteriorfield':   LLOp(sideeffects=False, canrun=True),
     'stm_become_inevitable':  LLOp(),
-    'stm_descriptor_init':    LLOp(),
-    'stm_descriptor_done':    LLOp(),
+    'stm_descriptor_init':    LLOp(canrun=True),
+    'stm_descriptor_done':    LLOp(canrun=True),
     'stm_writebarrier':       LLOp(sideeffects=False),
-    'stm_start_transaction':  LLOp(),
-    'stm_commit_transaction': LLOp(),
+    'stm_start_transaction':  LLOp(canrun=True),
+    'stm_commit_transaction': LLOp(canrun=True),
 
     # __________ address operations __________
 
diff --git a/pypy/rpython/lltypesystem/opimpl.py b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -608,6 +608,21 @@
     from pypy.rlib.rtimer import read_timestamp
     return read_timestamp()
 
+def op_stm_descriptor_init():
+    # for direct testing only
+    from pypy.translator.stm import stmgcintf
+    stmgcintf.StmOperations().set_tls(llmemory.NULL, 0)
+
+def op_stm_descriptor_done():
+    from pypy.translator.stm import stmgcintf
+    stmgcintf.StmOperations().del_tls()
+
+def op_stm_start_transaction():
+    pass
+
+def op_stm_commit_transaction():
+    pass
+
 # ____________________________________________________________
 
 def get_op_impl(opname):
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -503,7 +503,7 @@
 }
 
 
-static struct tx_descriptor *descriptor_init()
+static struct tx_descriptor *descriptor_init(long in_main_thread)
 {
   assert(thread_descriptor == NULL);
   assert(active_thread_descriptor == NULL);
@@ -516,11 +516,18 @@
       PYPY_DEBUG_START("stm-init");
 #endif
 
-      /* initialize 'my_lock_word' to be a unique negative number */
-      d->my_lock_word = (owner_version_t)d;
-      if (!IS_LOCKED(d->my_lock_word))
-        d->my_lock_word = ~d->my_lock_word;
-      assert(IS_LOCKED(d->my_lock_word));
+      if (in_main_thread)
+        {
+          d->my_lock_word = 0;   /* special value for the main thread */
+        }
+      else
+        {
+          /* initialize 'my_lock_word' to be a unique negative number */
+          d->my_lock_word = (owner_version_t)d;
+          if (!IS_LOCKED(d->my_lock_word))
+            d->my_lock_word = ~d->my_lock_word;
+          assert(IS_LOCKED(d->my_lock_word));
+        }
       /*d->spinloop_counter = (unsigned int)(d->my_lock_word | 1);*/
 
       thread_descriptor = d;
@@ -751,14 +758,15 @@
 long stm_thread_id(void)
 {
   struct tx_descriptor *d = thread_descriptor;
+  if (d == NULL)
+    return 0;    /* no thread_descriptor yet, assume it's the main thread */
   return d->my_lock_word;
 }
 
 
 void stm_set_tls(void *newtls, long in_main_thread)
 {
-  /* 'in_main_thread' is ignored so far */
-  struct tx_descriptor *d = descriptor_init();
+  struct tx_descriptor *d = descriptor_init(in_main_thread);
   d->rpython_tls_object = newtls;
 }
 


More information about the pypy-commit mailing list