summaryrefslogtreecommitdiff
path: root/libgo/runtime
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-22 00:12:00 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-22 00:12:00 +0000
commit573d42ad0f734af20d0311ae5bb327e67f42f394 (patch)
tree9c293c211f8d55d058e950363b288392bf35ea66 /libgo/runtime
parent3d16e887967eb96476482a70da3b23d8234a1a4c (diff)
downloadgcc-573d42ad0f734af20d0311ae5bb327e67f42f394.tar.gz
Avoid deadlock creating new thread.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@169114 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/runtime')
-rw-r--r--libgo/runtime/malloc.goc8
1 files changed, 8 insertions, 0 deletions
diff --git a/libgo/runtime/malloc.goc b/libgo/runtime/malloc.goc
index be37777d7bd..d826d479f5c 100644
--- a/libgo/runtime/malloc.goc
+++ b/libgo/runtime/malloc.goc
@@ -255,6 +255,9 @@ runtime_allocmcache(void)
{
MCache *c;
+ if(!__sync_bool_compare_and_swap(&m->mallocing, 0, 1))
+ runtime_throw("allocmcache - deadlock");
+
runtime_lock(&runtime_mheap);
c = runtime_FixAlloc_Alloc(&runtime_mheap.cachealloc);
@@ -264,6 +267,11 @@ runtime_allocmcache(void)
mstats.mcache_inuse = runtime_mheap.cachealloc.inuse;
mstats.mcache_sys = runtime_mheap.cachealloc.sys;
runtime_unlock(&runtime_mheap);
+
+ __sync_bool_compare_and_swap(&m->mallocing, 1, 0);
+ if(__sync_bool_compare_and_swap(&m->gcing, 1, 0))
+ __go_run_goroutine_gc(2);
+
return c;
}