diff mbox

[gccgo] Avoid another deadlock in GC when profiling

Message ID mcrr5hlknr6.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Aug. 26, 2010, 10:33 p.m. UTC
This patch avoids the other deadlock in GC when profiling: don't let
malloc continue the GC if it is invoked on behalf of the profiler.  The
last patch fixed the case where the GC asked the profiler to start the
GC, this patch fixes the case where the GC asks malloc to start the GC.
Committed to gccgo branch.

Ian
diff mbox

Patch

diff -r c4496094f7b1 libgo/runtime/malloc.goc
--- a/libgo/runtime/malloc.goc	Thu Aug 26 15:09:54 2010 -0700
+++ b/libgo/runtime/malloc.goc	Thu Aug 26 15:31:29 2010 -0700
@@ -99,8 +99,16 @@ 
 
 	__sync_bool_compare_and_swap(&m->mallocing, 1, 0);
 
-	if(__sync_bool_compare_and_swap(&m->gcing, 1, 0))
-		__go_run_goroutine_gc(0);
+	if(__sync_bool_compare_and_swap(&m->gcing, 1, 0)) {
+		if(!(refflag & RefNoProfiling))
+			__go_run_goroutine_gc(0);
+		else {
+			// We are being called from the profiler.  Tell it
+			// to invoke the garbage collector when it is
+			// done.  No need to use a sync function here.
+			m->gcing_for_prof = 1;
+		}
+	}
 
 	if(!(refflag & RefNoProfiling) && (rate = MemProfileRate) > 0) {
 		if(size >= (uint32) rate)