[pypy-commit] stmgc default: Fix a subtle issue

arigo noreply at buildbot.pypy.org
Mon May 27 15:31:14 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r39:c928b67403e8
Date: 2013-05-27 14:51 +0200
http://bitbucket.org/pypy/stmgc/changeset/c928b67403e8/

Log:	Fix a subtle issue

diff --git a/c3/gcpage.c b/c3/gcpage.c
--- a/c3/gcpage.c
+++ b/c3/gcpage.c
@@ -113,7 +113,7 @@
     stmgcpage_release_global_lock();
 }
 
-struct tx_descriptor *stm_find_thread_containing_pointer(gcptr L)
+struct tx_descriptor *stm_find_thread_containing_pointer_and_lock(gcptr L)
 {
     stmgcpage_acquire_global_lock();
 
@@ -126,6 +126,10 @@
     abort();
 
  found:
+    /* must acquire the collection_lock before releasing the global lock,
+       otherwise 'd' might be freed under our feet */
+    spinlock_acquire(d->collection_lock, 'S');  /* stealing */
+
     stmgcpage_release_global_lock();
     return d;
 }
diff --git a/c3/gcpage.h b/c3/gcpage.h
--- a/c3/gcpage.h
+++ b/c3/gcpage.h
@@ -76,7 +76,7 @@
 void stmgcpage_free(gcptr obj);
 void stmgcpage_add_prebuilt_root(gcptr obj);
 void stmgcpage_possibly_major_collect(int force);
-struct tx_descriptor *stm_find_thread_containing_pointer(gcptr);
+struct tx_descriptor *stm_find_thread_containing_pointer_and_lock(gcptr);
 
 extern struct GcPtrList stm_prebuilt_gcroots;
 
diff --git a/c3/nursery.c b/c3/nursery.c
--- a/c3/nursery.c
+++ b/c3/nursery.c
@@ -1030,11 +1030,13 @@
        thread's minor collection lock.  This also prevents several
        threads from getting on each other's toes trying to extract
        objects from the same nursery */
-    struct tx_descriptor *source_d = stm_find_thread_containing_pointer(R);
+    struct tx_descriptor *source_d;
+
+    /* source_d->collection_lock will be acquired with 'S' (stealing)
+       by the following call: */
+    source_d = stm_find_thread_containing_pointer_and_lock(R);
     assert(source_d != thread_descriptor);
 
-    spinlock_acquire(source_d->collection_lock, 'S');  /* stealing */
-
     /* now that we have the lock, check again that P->h_revision was not
        modified in the meantime.  If it did change, we do nothing and will
        retry.


More information about the pypy-commit mailing list