Commit d448d18c authored by Russ Cox's avatar Russ Cox

test and fix non-blocking chan ops on buffered chans

R=ken
DELTA=68  (19 added, 0 deleted, 49 changed)
OCL=15966
CL=15969
parent c3d841f5
......@@ -198,12 +198,18 @@ sendchan(Hchan *c, byte *ep, bool *pres)
sg = g->param;
freesg(c, sg);
unlock(&chanlock);
if(pres != nil)
*pres = true;
return;
asynch:
//prints("\nasend\n");
while(c->qcount >= c->dataqsiz) {
// (rsc) should check for pres != nil
if(pres != nil) {
unlock(&chanlock);
*pres = false;
return;
}
sg = allocsg(c);
g->status = Gwaiting;
enqueue(&c->sendq, sg);
......@@ -227,6 +233,8 @@ asynch:
ready(gp);
} else
unlock(&chanlock);
if(pres != nil)
*pres = true;
}
static void
......@@ -277,10 +285,17 @@ chanrecv(Hchan* c, byte *ep, bool* pres)
c->elemalg->copy(c->elemsize, ep, sg->elem);
freesg(c, sg);
unlock(&chanlock);
if(pres != nil)
*pres = true;
return;
asynch:
while(c->qcount <= 0) {
if(pres != nil) {
unlock(&chanlock);
*pres = false;
return;
}
sg = allocsg(c);
g->status = Gwaiting;
enqueue(&c->recvq, sg);
......@@ -300,6 +315,8 @@ asynch:
ready(gp);
} else
unlock(&chanlock);
if(pres != nil)
*pres = true;
}
// chansend1(hchan *chan any, elem any);
......
......@@ -52,10 +52,11 @@ func main() {
var s string;
var ok bool;
c32 := new(chan int32);
c64 := new(chan int64);
cb := new(chan bool);
cs := new(chan string);
for buffer := 0; buffer < 2; buffer++ {
c32 := new(chan int32, buffer);
c64 := new(chan int64, buffer);
cb := new(chan bool, buffer);
cs := new(chan string, buffer);
i32, ok = <-c32;
if ok { panic("blocked i32sender") }
......@@ -108,5 +109,6 @@ func main() {
s, ok = <-cs;
if !ok { panic("ssender") }
if s != "hello again" { panic("ssender value") }
}
print("PASS\n")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment