From: Dmitriy Vyukov Date: Mon, 3 Jun 2013 10:40:38 +0000 (+0400) Subject: runtime: disable preemption in several scheduler functions X-Git-Tag: go1.2rc2~1343 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4a8ef1f65db072ecd6ff79201338ac75b43640fa;p=gostls13.git runtime: disable preemption in several scheduler functions Required for preemptive scheduler, see the comments for details. R=golang-dev, khr, iant, khr CC=golang-dev https://golang.org/cl/9740051 --- diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 5b5d9b8a0b..c27d1f5f55 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -274,6 +274,7 @@ void runtime·ready(G *gp) { // Mark runnable. + m->locks++; // disable preemption because it can be holding p in a local var if(gp->status != Gwaiting) { runtime·printf("goroutine %D has status %d\n", gp->goid, gp->status); runtime·throw("bad g->status in ready"); @@ -282,6 +283,7 @@ runtime·ready(G *gp) runqput(m->p, gp); if(runtime·atomicload(&runtime·sched.npidle) != 0 && runtime·atomicload(&runtime·sched.nmspinning) == 0) // TODO: fast atomic wakep(); + m->locks--; } int32 @@ -398,6 +400,7 @@ runtime·starttheworld(void) G *gp; bool add; + m->locks++; // disable preemption because it can be holding p in a local var gp = runtime·netpoll(false); // non-blocking injectglist(gp); add = needaddgcproc(); @@ -451,6 +454,7 @@ runtime·starttheworld(void) // the maximum number of procs. newm(mhelpgc, nil); } + m->locks--; } // Called to start an M. @@ -1509,6 +1513,7 @@ runtime·newproc1(FuncVal *fn, byte *argp, int32 narg, int32 nret, void *callerp int32 siz; //runtime·printf("newproc1 %p %p narg=%d nret=%d\n", fn->fn, argp, narg, nret); + m->locks++; // disable preemption because it can be holding p in a local var siz = narg + nret; siz = (siz+7) & ~7; @@ -1555,6 +1560,7 @@ runtime·newproc1(FuncVal *fn, byte *argp, int32 narg, int32 nret, void *callerp if(runtime·atomicload(&runtime·sched.npidle) != 0 && runtime·atomicload(&runtime·sched.nmspinning) == 0 && fn->fn != runtime·main) // TODO: fast atomic wakep(); + m->locks--; return newg; }