Author: Remi Meier <[email protected]>
Branch: 
Changeset: r545:28f66a5356cd
Date: 2013-11-06 13:22 +0100
http://bitbucket.org/pypy/stmgc/changeset/28f66a5356cd/

Log:    allow nesting of stm_stop_all_other_threads()-stm_partial_commit_and
        _resume_other_threads() pairs

diff --git a/c4/stmsync.c b/c4/stmsync.c
--- a/c4/stmsync.c
+++ b/c4/stmsync.c
@@ -319,17 +319,21 @@
 }
 
 
+static int single_thread_nesting = 0;
 void stm_stop_all_other_threads(void)
 {                               /* push gc roots! */
     struct tx_descriptor *d;
 
     BecomeInevitable("stop_all_other_threads");
-    stm_start_single_thread();
-    
-    for (d = stm_tx_head; d; d = d->tx_next) {
-        if (*d->active_ref == 1) // && d != thread_descriptor) <- TRUE
-            AbortTransactionAfterCollect(d, ABRT_OTHER_THREADS);
+    if (!single_thread_nesting) {
+        stm_start_single_thread();
+        
+        for (d = stm_tx_head; d; d = d->tx_next) {
+            if (*d->active_ref == 1) // && d != thread_descriptor) <- TRUE
+                AbortTransactionAfterCollect(d, ABRT_OTHER_THREADS);
+        }
     }
+    single_thread_nesting++;
 }
 
 
@@ -339,20 +343,23 @@
     assert(stm_active == 2);
     int atomic = d->atomic;
 
-    /* Give up atomicity during commit. This still works because
-       we keep the inevitable status, thereby being guaranteed to 
-       commit before all others. */
-    stm_atomic(-atomic);
-
-    /* Commit and start new inevitable transaction while never
-       giving up the inevitable status. */
-    CommitTransaction(1);       /* 1=stay_inevitable! */
-    BeginInevitableTransaction(1);
-
-    /* restore atomic-count */
-    stm_atomic(atomic);
-
-    stm_stop_single_thread();
+    single_thread_nesting--;
+    if (single_thread_nesting == 0) {
+        /* Give up atomicity during commit. This still works because
+           we keep the inevitable status, thereby being guaranteed to 
+           commit before all others. */
+        stm_atomic(-atomic);
+        
+        /* Commit and start new inevitable transaction while never
+           giving up the inevitable status. */
+        CommitTransaction(1);       /* 1=stay_inevitable! */
+        BeginInevitableTransaction(1);
+        
+        /* restore atomic-count */
+        stm_atomic(atomic);
+        
+        stm_stop_single_thread();
+    }
 }
 
 void stm_start_single_thread(void)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to