From 7c79b5e434b93f07fda1853e06abafb3758b151f Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Thu, 27 Dec 2012 13:42:50 -0600 Subject: [PATCH] really update mandelbrot to pipes --- src/test/bench/shootout-mandelbrot.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index f85d6f6fdaa..7fe572b64f8 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -83,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 { rv } -fn chanmb(i: uint, size: uint, ch: oldcomm::Chan) -> () +fn chanmb(i: uint, size: uint) -> Line { let mut crv = ~[]; let incr = 2f64/(size as f64); @@ -93,7 +93,7 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan) -> () let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y}; crv.push(fillbyte(x, incr)); }; - oldcomm::send(ch, Line {i:i, b: move crv}); + Line {i:i, b:crv} } type devnull = {dn: int}; @@ -106,11 +106,8 @@ impl devnull: io::Writer { fn get_type(&self) -> io::WriterType { io::File } } -fn writer(path: ~str, writech: oldcomm::Chan>, size: uint) +fn writer(path: ~str, pport: pipes::Port, size: uint) { - let p: oldcomm::Port = oldcomm::Port(); - let ch = oldcomm::Chan(&p); - oldcomm::send(writech, ch); let cout: io::Writer = match path { ~"" => { {dn: 0} as io::Writer @@ -130,7 +127,7 @@ fn writer(path: ~str, writech: oldcomm::Chan>, size: uint) let mut done = 0_u; let mut i = 0_u; while i < size { - let aline = oldcomm::recv(p); + let aline = pport.recv(); if aline.i == done { debug!("W %u", aline.i); cout.write(aline.b); @@ -171,13 +168,11 @@ fn main() { let size = if vec::len(args) < 2_u { 80_u } else { uint::from_str(args[1]).get() }; - let writep = oldcomm::Port(); - let writech = oldcomm::Chan(&writep); - do task::spawn |move path| { - writer(copy path, writech, size); - }; - let ch = oldcomm::recv(writep); + let (pport, pchan) = pipes::stream(); + let pchan = pipes::SharedChan(pchan); 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); }