sys·panicl(123);
}
- newg = mal(sizeof(G));
- stk = mal(4096);
+ // try to rip off an old goroutine
+ for(newg=allg; newg!=nil; newg=newg->alllink)
+ if(newg->status == Gdead)
+ break;
+
+ if(newg == nil) {
+ newg = mal(sizeof(G));
+ stk = mal(4096);
+ newg->stack0 = stk;
+
+ newg->status = Gwaiting;
+ newg->alllink = allg;
+ allg = newg;
+ } else {
+ stk = newg->stack0;
+ newg->status = Gwaiting;
+ }
+
newg->stackguard = stk+160;
sp = stk + 4096 - 4*8;
newg->goid = goidgen;
newg->status = Grunnable;
- newg->alllink = allg;
- allg = newg;
//prints(" goid=");
//sys·printint(newg->goid);
G*
select(void)
{
- G *gp, *bestg;
+ G *gp;
- bestg = nil;
+ gp = m->lastg;
+ if(gp == nil)
+ gp = allg;
+
+ for(gp=gp->alllink; gp!=nil; gp=gp->alllink) {
+ if(gp->status == Grunnable) {
+ m->lastg = gp;
+ return gp;
+ }
+ }
for(gp=allg; gp!=nil; gp=gp->alllink) {
- if(gp->status != Grunnable)
- continue;
- if(bestg == nil || gp->pri < bestg->pri)
- bestg = gp;
+ if(gp->status == Grunnable) {
+ m->lastg = gp;
+ return gp;
+ }
}
- if(bestg != nil)
- bestg->pri++;
- return bestg;
+ return nil;
}
void
{
byte* stackguard; // must not move
byte* stackbase; // must not move
+ byte* stack0; // first stack segment
Gobuf sched;
G* alllink; // on allq
G* qlink; // on wait q
int32 status;
- int32 pri;
int32 goid;
byte elem[8]; // transfer element for chan
};
{
G* g0; // g0 w interrupt stack - must not move
uint64 morearg; // arg to morestack - must not move
- uint64 cret; // return value from C - must not move
+ uint64 cret; // return value from C - must not move
G* curg; // current running goroutine
+ G* lastg; // last running goroutine - to emulate fifo
Gobuf sched;
Gobuf morestack;
byte* moresp;