Commit 9c8f48bd authored by Rob Pike's avatar Rob Pike

use real select

R=ken
OCL=13519
CL=13519
parent 3835e01d
...@@ -75,49 +75,22 @@ func mkdch2() *dch2 { ...@@ -75,49 +75,22 @@ func mkdch2() *dch2 {
// generation to begin servicing out[1]. // generation to begin servicing out[1].
func dosplit(in *dch, out *dch2, wait *chan int ){ func dosplit(in *dch, out *dch2, wait *chan int ){
//print "dosplit ", wait, "\n";
var t *dch; var t *dch;
both := false; // do not service both channels both := false; // do not service both channels
/*
select { select {
case <-out[0].req: case <-out[0].req:
; ;
case <-wait: case <-wait:
both = 1; both = true;
select { select {
case <-out[0].req: case <-out[0].req:
; ;
case <-out[1].req: case <-out[1].req:
t=out[0]; out[0]=out[1]; out[1]=t; t=out[0]; out[0]=out[1]; out[1]=t;
};
}
*/
// select simulation
for {
var ok bool;
var dummy int;
dummy, ok = <-out[0].req;
if ok { goto OUT1 }
dummy, ok = <-wait;
if ok {
both = true;
// select simulation
for {
dummy, ok = <-out[0].req;
if ok { goto OUT1 }
dummy, ok = <-out[1].req;
if ok {
out[0], out[1] = out[1], out[0];
goto OUT1
}
sys.gosched();
}
} }
sys.gosched();
} }
OUT1: //BUG
seqno++; seqno++;
in.req -< seqno; in.req -< seqno;
release := new(chan int); release := new(chan int);
...@@ -165,42 +138,21 @@ func getn(in *[]*dch, n int) *[]item { ...@@ -165,42 +138,21 @@ func getn(in *[]*dch, n int) *[]item {
} }
for n=2*n; n>0; n-- { for n=2*n; n>0; n-- {
seqno++ seqno++
/*
select{
case req[i=] <-= seqno:
dat[i] = in[i].dat;
req[i] = nil;
case it = <-dat[i=]:
out[i] = it;
dat[i] = nil;
}
*/
// simulation of select select{
sel: case req[0] -< seqno:
for c1:=0; ; c1++ { dat[0] = in[0].dat;
for i := 0; i < 2; i++ { req[0] = nil;
ok := false; case req[1] -< seqno:
if req[i] != nil { ok = req[i] -< seqno } dat[1] = in[1].dat;
if ok { req[1] = nil;
dat[i] = in[i].dat; case it <- dat[0]:
req[i] = nil; out[0] = it;
goto OUT; // BUG dat[0] = nil;
break sel; case it <- dat[1]:
} out[1] = it;
ok = false; dat[1] = nil;
if dat[i] != nil { it, ok = <-dat[i] }
if ok {
out[i] = it;
dat[i] = nil;
goto OUT; // BUG
break sel;
}
sys.gosched();
}
sys.gosched();
} }
OUT:
} }
return out; return out;
} }
...@@ -251,7 +203,6 @@ func mkPS2() *dch2 { ...@@ -251,7 +203,6 @@ func mkPS2() *dch2 {
func gcd (u, v int64) int64{ func gcd (u, v int64) int64{
if u < 0 { return gcd(-u, v) } if u < 0 { return gcd(-u, v) }
if u > v { return gcd(v, u) }
if u == 0 { return v } if u == 0 { return v }
return gcd(v%u, u) return gcd(v%u, u)
} }
......
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