Author: Tobias Weber <tobias_webe...@gmx.de>
Branch: c8-adaptive-trx-length-per-thread
Changeset: r2091:d36657eedf72
Date: 2017-07-04 16:01 +0200
http://bitbucket.org/pypy/stmgc/changeset/d36657eedf72/

Log:    Merge aggressive wait when becoming inevitable

diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -1638,7 +1638,7 @@
 
 void _stm_become_inevitable(const char *msg)
 {
-    int num_waits = 0;
+    int num_waits = NB_SEGMENTS; //0;
 
     timing_become_inevitable();
 
@@ -1655,8 +1655,6 @@
             stm_abort_transaction();    /*   is already inevitable, abort */
 #endif
 
-            bool timed_out = false;
-
             s_mutex_lock();
             if (any_soon_finished_or_inevitable_thread_segment() &&
                     !safe_point_requested()) {
@@ -1665,36 +1663,34 @@
 
                 /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */
                 EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE);
-                if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ,
-                                       0.000054321))
-                    timed_out = true;
+                if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 
0.00001)) {
+                    s_mutex_unlock();
+                    /* try to detach another inevitable transaction, but
+                      only after waiting a bit.  This is necessary to avoid
+                      deadlocks in some situations, which are hopefully
+                      not too common.  We don't want two threads constantly
+                      detaching each other. */
+                    intptr_t detached = fetch_detached_transaction();
+                    if (detached != 0) {
+                       EMIT_WAIT_DONE();
+                       commit_fetched_detached_transaction(detached);
+                    }
+                    goto retry_from_start;
+                }
+                num_waits++;
             }
             s_mutex_unlock();
-
-            if (timed_out) {
-                /* try to detach another inevitable transaction, but
-                   only after waiting a bit.  This is necessary to avoid
-                   deadlocks in some situations, which are hopefully
-                   not too common.  We don't want two threads constantly
-                   detaching each other. */
-                intptr_t detached = fetch_detached_transaction();
-                if (detached != 0) {
-                    EMIT_WAIT_DONE();
-                    commit_fetched_detached_transaction(detached);
-                }
-            }
-            else {
-                num_waits++;
-            }
             goto retry_from_start;
         }
-        EMIT_WAIT_DONE();
-        if (!_validate_and_turn_inevitable())
-            goto retry_from_start;
+        else {
+            EMIT_WAIT_DONE();
+            if (!_validate_and_turn_inevitable()) {
+                goto retry_from_start;
+            }
+        }
     }
-    else {
-        if (!_validate_and_turn_inevitable())
-            return;
+    else if (!_validate_and_turn_inevitable()) {
+        return;
     }
 
     /* There may be a concurrent commit of a detached Tx going on.
diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c
--- a/c8/stm/nursery.c
+++ b/c8/stm/nursery.c
@@ -542,8 +542,10 @@
     pseg->pub.nursery_current = (stm_char *)_stm_nursery_start;
     pseg->pub.nursery_mark -= nursery_used;
 
-    if (pseg->commit_if_not_atomic && 
pseg->pub.running_thread->self_or_0_if_atomic != 0) {
-        // not atomic and commit signalled by waiting thread: commit 
immediately
+    if (pseg->commit_if_not_atomic
+        // && pseg->transaction_state == TS_INEVITABLE // TODO why does this 
break the mechanism? 
+        && pseg->pub.running_thread->self_or_0_if_atomic != 0) {
+        // transaction is inevitable, not atomic, and commit has been 
signalled by waiting thread: commit immediately
         pseg->pub.nursery_mark = 0;
     }
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to