really update mandelbrot to pipes
This commit is contained in:
parent
b169889005
commit
7c79b5e434
1 changed files with 9 additions and 14 deletions
|
@ -83,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
|
||||||
rv
|
rv
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
|
fn chanmb(i: uint, size: uint) -> Line
|
||||||
{
|
{
|
||||||
let mut crv = ~[];
|
let mut crv = ~[];
|
||||||
let incr = 2f64/(size as f64);
|
let incr = 2f64/(size as f64);
|
||||||
|
@ -93,7 +93,7 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
|
||||||
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
|
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
|
||||||
crv.push(fillbyte(x, incr));
|
crv.push(fillbyte(x, incr));
|
||||||
};
|
};
|
||||||
oldcomm::send(ch, Line {i:i, b: move crv});
|
Line {i:i, b:crv}
|
||||||
}
|
}
|
||||||
|
|
||||||
type devnull = {dn: int};
|
type devnull = {dn: int};
|
||||||
|
@ -106,11 +106,8 @@ impl devnull: io::Writer {
|
||||||
fn get_type(&self) -> io::WriterType { io::File }
|
fn get_type(&self) -> io::WriterType { io::File }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
|
fn writer(path: ~str, pport: pipes::Port<Line>, size: uint)
|
||||||
{
|
{
|
||||||
let p: oldcomm::Port<Line> = oldcomm::Port();
|
|
||||||
let ch = oldcomm::Chan(&p);
|
|
||||||
oldcomm::send(writech, ch);
|
|
||||||
let cout: io::Writer = match path {
|
let cout: io::Writer = match path {
|
||||||
~"" => {
|
~"" => {
|
||||||
{dn: 0} as io::Writer
|
{dn: 0} as io::Writer
|
||||||
|
@ -130,7 +127,7 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
|
||||||
let mut done = 0_u;
|
let mut done = 0_u;
|
||||||
let mut i = 0_u;
|
let mut i = 0_u;
|
||||||
while i < size {
|
while i < size {
|
||||||
let aline = oldcomm::recv(p);
|
let aline = pport.recv();
|
||||||
if aline.i == done {
|
if aline.i == done {
|
||||||
debug!("W %u", aline.i);
|
debug!("W %u", aline.i);
|
||||||
cout.write(aline.b);
|
cout.write(aline.b);
|
||||||
|
@ -171,13 +168,11 @@ fn main() {
|
||||||
let size = if vec::len(args) < 2_u { 80_u }
|
let size = if vec::len(args) < 2_u { 80_u }
|
||||||
else { uint::from_str(args[1]).get() };
|
else { uint::from_str(args[1]).get() };
|
||||||
|
|
||||||
let writep = oldcomm::Port();
|
let (pport, pchan) = pipes::stream();
|
||||||
let writech = oldcomm::Chan(&writep);
|
let pchan = pipes::SharedChan(pchan);
|
||||||
do task::spawn |move path| {
|
|
||||||
writer(copy path, writech, size);
|
|
||||||
};
|
|
||||||
let ch = oldcomm::recv(writep);
|
|
||||||
for uint::range(0_u, size) |j| {
|
for uint::range(0_u, size) |j| {
|
||||||
do task::spawn { chanmb(j, size, ch) };
|
let cchan = pchan.clone();
|
||||||
|
do task::spawn |move cchan| { cchan.send(chanmb(j, size)) };
|
||||||
};
|
};
|
||||||
|
writer(path, pport, size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue