@@ -43,10 +43,9 @@ use cmp;
4343use cmp:: Eq ;
4444use iter;
4545use libc;
46- use oldcomm;
4746use option;
4847use result:: Result ;
49- use pipes:: { stream, Chan , Port } ;
48+ use pipes:: { stream, Chan , Port , SharedChan } ;
5049use pipes;
5150use prelude:: * ;
5251use ptr;
@@ -427,18 +426,17 @@ impl TaskBuilder {
427426 * Fails if a future_result was already set for this task.
428427 */
429428 fn try<T: Owned>(f: fn~() -> T) -> Result<T,()> {
430- let po = oldcomm::Port();
431- let ch = oldcomm::Chan(&po);
429+ let (po, ch) = stream::<T>();
432430 let mut result = None;
433431
434432 let fr_task_builder = self.future_result(|+r| {
435433 result = Some(move r);
436434 });
437- do fr_task_builder.spawn |move f| {
438- oldcomm:: send(ch, f());
435+ do fr_task_builder.spawn |move f, move ch | {
436+ ch. send(f());
439437 }
440438 match option::unwrap(move result).recv() {
441- Success => result::Ok(oldcomm:: recv(po )),
439+ Success => result::Ok(po. recv()),
442440 Failure => result::Err(())
443441 }
444442 }
@@ -665,17 +663,18 @@ fn test_cant_dup_task_builder() {
665663
666664#[ test] #[ ignore( cfg( windows) ) ]
667665fn test_spawn_unlinked_unsup_no_fail_down( ) { // grandchild sends on a port
668- let po = oldcomm : : Port ( ) ;
669- let ch = oldcomm :: Chan ( & po ) ;
666+ let ( po , ch ) = stream ( ) ;
667+ let ch = SharedChan ( ch ) ;
670668 do spawn_unlinked {
669+ let ch = ch. clone( ) ;
671670 do spawn_unlinked {
672671 // Give middle task a chance to fail-but-not-kill-us.
673672 for iter:: repeat( 16 ) { task:: yield( ) ; }
674- oldcomm :: send( ch , ( ) ) ; // If killed first, grandparent hangs.
673+ ch . send( ( ) ) ; // If killed first, grandparent hangs.
675674 }
676675 fail; // Shouldn't kill either (grand)parent or (grand)child.
677676 }
678- oldcomm :: recv( po ) ;
677+ po . recv( ) ;
679678}
680679#[ test] #[ ignore( cfg( windows) ) ]
681680fn test_spawn_unlinked_unsup_no_fail_up( ) { // child unlinked fails
@@ -695,8 +694,7 @@ fn test_spawn_unlinked_sup_fail_down() {
695694
696695#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
697696fn test_spawn_linked_sup_fail_up( ) { // child fails; parent fails
698- let po = oldcomm : : Port :: < ( ) > ( ) ;
699- let _ch = oldcomm:: Chan ( & po) ;
697+ let ( po, _ch) = stream :: < ( ) > ( ) ;
700698 // Unidirectional "parenting" shouldn't override bidirectional linked.
701699 // We have to cheat with opts - the interface doesn't support them because
702700 // they don't make sense (redundant with task().supervised()).
@@ -714,7 +712,7 @@ fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
714712 .. b0
715713 } ;
716714 do b1. spawn { fail; }
717- oldcomm :: recv( po ) ; // We should get punted awake
715+ po . recv( ) ; // We should get punted awake
718716}
719717#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
720718fn test_spawn_linked_sup_fail_down( ) { // parent fails; child fails
@@ -738,11 +736,10 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
738736}
739737#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
740738fn test_spawn_linked_unsup_fail_up( ) { // child fails; parent fails
741- let po = oldcomm : : Port :: < ( ) > ( ) ;
742- let _ch = oldcomm:: Chan ( & po) ;
739+ let ( po, _ch) = stream :: < ( ) > ( ) ;
743740 // Default options are to spawn linked & unsupervised.
744741 do spawn { fail; }
745- oldcomm :: recv( po ) ; // We should get punted awake
742+ po . recv( ) ; // We should get punted awake
746743}
747744#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
748745fn test_spawn_linked_unsup_fail_down( ) { // parent fails; child fails
@@ -810,27 +807,25 @@ fn test_spawn_linked_sup_propagate_sibling() {
810807
811808#[ test]
812809fn test_run_basic( ) {
813- let po = oldcomm : : Port ( ) ;
814- let ch = oldcomm:: Chan ( & po) ;
810+ let ( po, ch) = stream :: < ( ) > ( ) ;
815811 do task( ) . spawn {
816- oldcomm : : send( ch , ( ) ) ;
812+ ch . send( ( ) ) ;
817813 }
818- oldcomm :: recv( po ) ;
814+ po . recv( ) ;
819815}
820816
821817#[ test]
822818fn test_add_wrapper( ) {
823- let po = oldcomm : : Port ( ) ;
824- let ch = oldcomm:: Chan ( & po) ;
819+ let ( po, ch) = stream :: < ( ) > ( ) ;
825820 let b0 = task( ) ;
826821 let b1 = do b0. add_wrapper |body| {
827822 fn ~( move body) {
828823 body( ) ;
829- oldcomm :: send( ch , ( ) ) ;
824+ ch . send( ( ) ) ;
830825 }
831826 } ;
832827 do b1. spawn { }
833- oldcomm :: recv( po ) ;
828+ po . recv( ) ;
834829}
835830
836831#[ test]
@@ -883,32 +878,31 @@ fn test_spawn_sched_no_threads() {
883878
884879#[ test]
885880fn test_spawn_sched( ) {
886- let po = oldcomm : : Port ( ) ;
887- let ch = oldcomm :: Chan ( & po ) ;
881+ let ( po , ch ) = stream :: < ( ) > ( ) ;
882+ let ch = SharedChan ( ch ) ;
888883
889- fn f( i: int, ch: oldcomm :: Chan < ( ) > ) {
884+ fn f( i: int, ch: SharedChan < ( ) > ) {
890885 let parent_sched_id = rt:: rust_get_sched_id( ) ;
891886
892887 do spawn_sched( SingleThreaded ) {
893888 let child_sched_id = rt:: rust_get_sched_id( ) ;
894889 assert parent_sched_id != child_sched_id;
895890
896891 if ( i == 0 ) {
897- oldcomm :: send( ch , ( ) ) ;
892+ ch . send( ( ) ) ;
898893 } else {
899- f( i - 1 , ch) ;
894+ f( i - 1 , ch. clone ( ) ) ;
900895 }
901896 } ;
902897
903898 }
904899 f( 10 , ch) ;
905- oldcomm :: recv( po ) ;
900+ po . recv( ) ;
906901}
907902
908903#[ test]
909904fn test_spawn_sched_childs_on_default_sched( ) {
910- let po = oldcomm : : Port ( ) ;
911- let ch = oldcomm:: Chan ( & po) ;
905+ let ( po, ch) = stream( ) ;
912906
913907 // Assuming tests run on the default scheduler
914908 let default_id = rt:: rust_get_sched_id( ) ;
@@ -919,11 +913,11 @@ fn test_spawn_sched_childs_on_default_sched() {
919913 let child_sched_id = rt : : rust_get_sched_id( ) ;
920914 assert parent_sched_id != child_sched_id;
921915 assert child_sched_id == default_id;
922- oldcomm :: send( ch , ( ) ) ;
916+ ch . send( ( ) ) ;
923917 } ;
924918 } ;
925919
926- oldcomm :: recv( po ) ;
920+ po . recv( ) ;
927921}
928922
929923#[ nolink]
@@ -945,74 +939,69 @@ fn test_spawn_sched_blocking() {
945939 // without affecting other schedulers
946940 for iter:: repeat( 20 u) {
947941
948- let start_po = oldcomm:: Port ( ) ;
949- let start_ch = oldcomm:: Chan ( & start_po) ;
950- let fin_po = oldcomm:: Port ( ) ;
951- let fin_ch = oldcomm:: Chan ( & fin_po) ;
942+ let ( start_po, start_ch) = stream( ) ;
943+ let ( fin_po, fin_ch) = stream( ) ;
952944
953945 let lock = testrt:: rust_dbg_lock_create( ) ;
954946
955947 do spawn_sched( SingleThreaded ) {
956948 unsafe {
957949 testrt:: rust_dbg_lock_lock( lock) ;
958950
959- oldcomm :: send( start_ch , ( ) ) ;
951+ start_ch . send( ( ) ) ;
960952
961953 // Block the scheduler thread
962954 testrt:: rust_dbg_lock_wait( lock) ;
963955 testrt:: rust_dbg_lock_unlock( lock) ;
964956
965- oldcomm :: send( fin_ch , ( ) ) ;
957+ fin_ch . send( ( ) ) ;
966958 }
967959 } ;
968960
969961 // Wait until the other task has its lock
970- oldcomm :: recv( start_po ) ;
962+ start_po . recv( ) ;
971963
972- fn pingpong( po: oldcomm :: Port < int > , ch: oldcomm :: Chan < int > ) {
964+ fn pingpong( po: & Port < int > , ch: & Chan < int > ) {
973965 let mut val = 20 ;
974966 while val > 0 {
975- val = oldcomm :: recv( po ) ;
976- oldcomm :: send( ch , val - 1 ) ;
967+ val = po . recv( ) ;
968+ ch . send( val - 1 ) ;
977969 }
978970 }
979971
980- let setup_po = oldcomm:: Port ( ) ;
981- let setup_ch = oldcomm:: Chan ( & setup_po) ;
982- let parent_po = oldcomm:: Port ( ) ;
983- let parent_ch = oldcomm:: Chan ( & parent_po) ;
972+ let ( setup_po, setup_ch) = stream( ) ;
973+ let ( parent_po, parent_ch) = stream( ) ;
984974 do spawn {
985- let child_po = oldcomm : : Port ( ) ;
986- oldcomm :: send( setup_ch , oldcomm :: Chan ( & child_po ) ) ;
987- pingpong( child_po, parent_ch) ;
975+ let ( child_po, child_ch ) = stream ( ) ;
976+ setup_ch . send( child_ch ) ;
977+ pingpong( & child_po, & parent_ch) ;
988978 } ;
989979
990- let child_ch = oldcomm :: recv( setup_po ) ;
991- oldcomm :: send( child_ch , 20 ) ;
992- pingpong( parent_po, child_ch) ;
980+ let child_ch = setup_po . recv( ) ;
981+ child_ch . send( 20 ) ;
982+ pingpong( & parent_po, & child_ch) ;
993983 testrt:: rust_dbg_lock_lock( lock) ;
994984 testrt:: rust_dbg_lock_signal( lock) ;
995985 testrt:: rust_dbg_lock_unlock( lock) ;
996- oldcomm :: recv( fin_po ) ;
986+ fin_po . recv( ) ;
997987 testrt:: rust_dbg_lock_destroy( lock) ;
998988 }
999989 }
1000990}
1001991
1002992#[ cfg( test) ]
1003993fn avoid_copying_the_body( spawnfn: fn ( v: fn ~( ) ) ) {
1004- let p = oldcomm:: Port :: < uint > ( ) ;
1005- let ch = oldcomm:: Chan ( & p) ;
994+ let ( p, ch) = stream :: < uint > ( ) ;
1006995
1007996 let x = ~1 ;
1008997 let x_in_parent = ptr:: addr_of( & ( * x) ) as uint;
1009998
1010999 do spawnfn |move x| {
10111000 let x_in_child = ptr:: addr_of( & ( * x) ) as uint;
1012- oldcomm :: send( ch , x_in_child) ;
1001+ ch . send( x_in_child) ;
10131002 }
10141003
1015- let x_in_child = oldcomm :: recv( p ) ;
1004+ let x_in_child = p . recv( ) ;
10161005 assert x_in_parent == x_in_child;
10171006}
10181007
@@ -1050,20 +1039,18 @@ fn test_avoid_copying_the_body_unlinked() {
10501039
10511040#[ test]
10521041fn test_platform_thread( ) {
1053- let po = oldcomm : : Port ( ) ;
1054- let ch = oldcomm:: Chan ( & po) ;
1042+ let ( po, ch) = stream( ) ;
10551043 do task( ) . sched_mode( PlatformThread ) . spawn {
1056- oldcomm : : send( ch , ( ) ) ;
1044+ ch . send( ( ) ) ;
10571045 }
1058- oldcomm :: recv( po ) ;
1046+ po . recv( ) ;
10591047}
10601048
10611049#[ test]
10621050#[ ignore( cfg( windows) ) ]
10631051#[ should_fail]
10641052fn test_unkillable( ) {
1065- let po = oldcomm : : Port ( ) ;
1066- let ch = po. chan( ) ;
1053+ let ( po, ch) = stream( ) ;
10671054
10681055 // We want to do this after failing
10691056 do spawn_unlinked {
0 commit comments