Author: Armin Rigo <[email protected]>
Branch: c8-gil-like
Changeset: r1797:152b52431340
Date: 2015-06-10 16:51 +0200
http://bitbucket.org/pypy/stmgc/changeset/152b52431340/

Log:    fix fix fix

diff --git a/c8/demo/demo_simple.c b/c8/demo/demo_simple.c
--- a/c8/demo/demo_simple.c
+++ b/c8/demo/demo_simple.c
@@ -70,18 +70,20 @@
 
     object_t *tmp;
     int i = 0;
+
+    stm_enter_transactional_zone(&stm_thread_local);
     while (i < ITERS) {
-        stm_start_transaction(&stm_thread_local);
         tl_counter++;
         if (i % 500 < 250)
             STM_PUSH_ROOT(stm_thread_local, stm_allocate(16));//gl_counter++;
         else
             STM_POP_ROOT(stm_thread_local, tmp);
-        stm_commit_transaction();
+        stm_force_transaction_break(&stm_thread_local);
         i++;
     }
 
     OPT_ASSERT(org == (char *)stm_thread_local.shadowstack);
+    stm_leave_transactional_zone(&stm_thread_local);
 
     stm_rewind_jmp_leaveframe(&stm_thread_local, &rjbuf);
     stm_unregister_thread_local(&stm_thread_local);
diff --git a/c8/demo/test_shadowstack.c b/c8/demo/test_shadowstack.c
--- a/c8/demo/test_shadowstack.c
+++ b/c8/demo/test_shadowstack.c
@@ -43,17 +43,16 @@
     stm_register_thread_local(&stm_thread_local);
     stm_rewind_jmp_enterframe(&stm_thread_local, &rjbuf);
 
-    stm_start_transaction(&stm_thread_local);
+    stm_enter_transactional_zone(&stm_thread_local);
     node_t *node = (node_t *)stm_allocate(sizeof(struct node_s));
     node->value = 129821;
     STM_PUSH_ROOT(stm_thread_local, node);
     STM_PUSH_ROOT(stm_thread_local, 333);  /* odd value */
-    stm_commit_transaction();
 
     /* now in a new transaction, pop the node off the shadowstack, but
        then do a major collection.  It should still be found by the
        tracing logic. */
-    stm_start_transaction(&stm_thread_local);
+    stm_force_transaction_break(&stm_thread_local);
     STM_POP_ROOT_RET(stm_thread_local);
     STM_POP_ROOT(stm_thread_local, node);
     assert(node->value == 129821);
diff --git a/c8/stm/detach.c b/c8/stm/detach.c
--- a/c8/stm/detach.c
+++ b/c8/stm/detach.c
@@ -40,6 +40,12 @@
 
 void _stm_reattach_transaction(uintptr_t old, stm_thread_local_t *tl)
 {
+    if (old == 0) {
+        /* there was no detached inevitable transaction */
+        _stm_start_transaction(tl);
+        return;
+    }
+
     if (old & 1) {
         /* The detached transaction was fetched; wait until the s_mutex_lock
            is free. 
@@ -56,21 +62,15 @@
         s_mutex_unlock();
     }
 
-    if (old != 0) {
-        /* We took over the inevitable transaction originally detached
-           from a different thread.  We have to fix the %gs register if
-           it is incorrect.
-        */
-        ensure_gs_register(tl->last_associated_segment_num);
-        assert(STM_SEGMENT->running_thread == (stm_thread_local_t *)old);
-        STM_SEGMENT->running_thread = tl;
+    /* We took over the inevitable transaction originally detached
+       from a different thread.  We have to fix the %gs register if
+       it is incorrect.
+    */
+    ensure_gs_register(tl->last_associated_segment_num);
+    assert(STM_SEGMENT->running_thread == (stm_thread_local_t *)old);
+    STM_SEGMENT->running_thread = tl;
 
-        stm_safe_point();
-    }
-    else {
-        /* there was no detached inevitable transaction */
-        _stm_start_transaction(tl);
-    }
+    stm_safe_point();
 }
 
 static bool fetch_detached_transaction(void)
@@ -108,3 +108,10 @@
     pseg->safe_point = SP_RUNNING_DETACHED_FETCHED;
     return true;
 }
+
+void stm_force_transaction_break(stm_thread_local_t *tl)
+{
+    assert(STM_SEGMENT->running_thread == tl);
+    _stm_commit_transaction();
+    _stm_start_transaction(tl);
+}
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -433,13 +433,13 @@
         _stm_leave_noninevitable_transactional_zone();
 }
 
-/* stm_break_transaction() is in theory equivalent to
+/* stm_force_transaction_break() is in theory equivalent to
    stm_leave_transactional_zone() immediately followed by
    stm_enter_transactional_zone(); however, it is supposed to be
    called in CPU-heavy threads that had a transaction run for a while,
    and so it *always* forces a commit and starts the next transaction.
    The new transaction is never inevitable. */
-void stm_break_transaction(stm_thread_local_t *tl);
+void stm_force_transaction_break(stm_thread_local_t *tl);
 
 /* Abort the currently running transaction.  This function never
    returns: it jumps back to the start of the transaction (which must
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to