1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:30:25 -07:00

runtime support for default in select.

assumes cas->send == 2 for default case.

R=ken
OCL=18628
CL=18628
This commit is contained in:
Russ Cox 2008-11-05 17:57:18 -08:00
parent d6a7cefd1e
commit b69e80d8dd

View File

@ -52,7 +52,7 @@ struct Scase
{
Hchan* chan; // chan
byte* pc; // return pc
uint16 send; // 0-recv 1-send
uint16 send; // 0-recv 1-send 2-default
uint16 so; // vararg of selected bool
union {
byte elem[8]; // element (send)
@ -504,7 +504,7 @@ void
sys·selectgo(Select *sel)
{
uint32 p, o, i;
Scase *cas;
Scase *cas, *dfl;
Hchan *c;
SudoG *sg;
G *gp;
@ -542,8 +542,13 @@ sys·selectgo(Select *sel)
lock(&chanlock);
// pass 1 - look for something already waiting
dfl = nil;
for(i=0; i<sel->ncase; i++) {
cas = &sel->scase[o];
if(cas->send == 2) { // default
dfl = cas;
continue;
}
c = cas->chan;
if(c->dataqsiz > 0) {
if(cas->send) {
@ -570,6 +575,12 @@ sys·selectgo(Select *sel)
o -= sel->ncase;
}
if(dfl != nil) {
cas = dfl;
goto retc;
}
// pass 2 - enqueue on all chans
for(i=0; i<sel->ncase; i++) {
cas = &sel->scase[o];