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) ...@@ -198,12 +198,18 @@ sendchan(Hchan *c, byte *ep, bool *pres)
sg = g->param; sg = g->param;
freesg(c, sg); freesg(c, sg);
unlock(&chanlock); unlock(&chanlock);
if(pres != nil)
*pres = true;
return; return;
asynch: asynch:
//prints("\nasend\n"); //prints("\nasend\n");
while(c->qcount >= c->dataqsiz) { while(c->qcount >= c->dataqsiz) {
// (rsc) should check for pres != nil if(pres != nil) {
unlock(&chanlock);
*pres = false;
return;
}
sg = allocsg(c); sg = allocsg(c);
g->status = Gwaiting; g->status = Gwaiting;
enqueue(&c->sendq, sg); enqueue(&c->sendq, sg);
...@@ -227,6 +233,8 @@ asynch: ...@@ -227,6 +233,8 @@ asynch:
ready(gp); ready(gp);
} else } else
unlock(&chanlock); unlock(&chanlock);
if(pres != nil)
*pres = true;
} }
static void static void
...@@ -277,10 +285,17 @@ chanrecv(Hchan* c, byte *ep, bool* pres) ...@@ -277,10 +285,17 @@ chanrecv(Hchan* c, byte *ep, bool* pres)
c->elemalg->copy(c->elemsize, ep, sg->elem); c->elemalg->copy(c->elemsize, ep, sg->elem);
freesg(c, sg); freesg(c, sg);
unlock(&chanlock); unlock(&chanlock);
if(pres != nil)
*pres = true;
return; return;
asynch: asynch:
while(c->qcount <= 0) { while(c->qcount <= 0) {
if(pres != nil) {
unlock(&chanlock);
*pres = false;
return;
}
sg = allocsg(c); sg = allocsg(c);
g->status = Gwaiting; g->status = Gwaiting;
enqueue(&c->recvq, sg); enqueue(&c->recvq, sg);
...@@ -300,6 +315,8 @@ asynch: ...@@ -300,6 +315,8 @@ asynch:
ready(gp); ready(gp);
} else } else
unlock(&chanlock); unlock(&chanlock);
if(pres != nil)
*pres = true;
} }
// chansend1(hchan *chan any, elem any); // chansend1(hchan *chan any, elem any);
......
...@@ -52,10 +52,11 @@ func main() { ...@@ -52,10 +52,11 @@ func main() {
var s string; var s string;
var ok bool; var ok bool;
c32 := new(chan int32); for buffer := 0; buffer < 2; buffer++ {
c64 := new(chan int64); c32 := new(chan int32, buffer);
cb := new(chan bool); c64 := new(chan int64, buffer);
cs := new(chan string); cb := new(chan bool, buffer);
cs := new(chan string, buffer);
i32, ok = <-c32; i32, ok = <-c32;
if ok { panic("blocked i32sender") } if ok { panic("blocked i32sender") }
...@@ -108,5 +109,6 @@ func main() { ...@@ -108,5 +109,6 @@ func main() {
s, ok = <-cs; s, ok = <-cs;
if !ok { panic("ssender") } if !ok { panic("ssender") }
if s != "hello again" { panic("ssender value") } if s != "hello again" { panic("ssender value") }
}
print("PASS\n") 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