Commits

Armin Rigo committed 25a1c74

Fix fix fix.

Comments (0)

Files changed (5)

pypy/module/transaction/interp_transaction.py

         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
             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
     #
     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

pypy/rlib/rstm.py

 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,
             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)
 
 @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)

pypy/rpython/lltypesystem/lloperation.py

     '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 __________
 

pypy/rpython/lltypesystem/opimpl.py

     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):

pypy/translator/stm/src_stm/et.c

 }
 
 
-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);
       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;
 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;
 }