@@ -43,10 +43,9 @@ use cmp;
43
43
use cmp:: Eq ;
44
44
use iter;
45
45
use libc;
46
- use oldcomm;
47
46
use option;
48
47
use result:: Result ;
49
- use pipes:: { stream, Chan , Port } ;
48
+ use pipes:: { stream, Chan , Port , SharedChan } ;
50
49
use pipes;
51
50
use prelude:: * ;
52
51
use ptr;
@@ -427,18 +426,17 @@ impl TaskBuilder {
427
426
* Fails if a future_result was already set for this task.
428
427
*/
429
428
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>();
432
430
let mut result = None;
433
431
434
432
let fr_task_builder = self.future_result(|+r| {
435
433
result = Some(move r);
436
434
});
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());
439
437
}
440
438
match option::unwrap(move result).recv() {
441
- Success => result::Ok(oldcomm:: recv(po )),
439
+ Success => result::Ok(po. recv()),
442
440
Failure => result::Err(())
443
441
}
444
442
}
@@ -665,17 +663,18 @@ fn test_cant_dup_task_builder() {
665
663
666
664
#[ test] #[ ignore( cfg( windows) ) ]
667
665
fn 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 ) ;
670
668
do spawn_unlinked {
669
+ let ch = ch. clone( ) ;
671
670
do spawn_unlinked {
672
671
// Give middle task a chance to fail-but-not-kill-us.
673
672
for iter:: repeat( 16 ) { task:: yield( ) ; }
674
- oldcomm :: send( ch , ( ) ) ; // If killed first, grandparent hangs.
673
+ ch . send( ( ) ) ; // If killed first, grandparent hangs.
675
674
}
676
675
fail; // Shouldn't kill either (grand)parent or (grand)child.
677
676
}
678
- oldcomm :: recv( po ) ;
677
+ po . recv( ) ;
679
678
}
680
679
#[ test] #[ ignore( cfg( windows) ) ]
681
680
fn test_spawn_unlinked_unsup_no_fail_up( ) { // child unlinked fails
@@ -695,8 +694,7 @@ fn test_spawn_unlinked_sup_fail_down() {
695
694
696
695
#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
697
696
fn 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 :: < ( ) > ( ) ;
700
698
// Unidirectional "parenting" shouldn't override bidirectional linked.
701
699
// We have to cheat with opts - the interface doesn't support them because
702
700
// they don't make sense (redundant with task().supervised()).
@@ -714,7 +712,7 @@ fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
714
712
.. b0
715
713
} ;
716
714
do b1. spawn { fail; }
717
- oldcomm :: recv( po ) ; // We should get punted awake
715
+ po . recv( ) ; // We should get punted awake
718
716
}
719
717
#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
720
718
fn 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
738
736
}
739
737
#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
740
738
fn 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 :: < ( ) > ( ) ;
743
740
// Default options are to spawn linked & unsupervised.
744
741
do spawn { fail; }
745
- oldcomm :: recv( po ) ; // We should get punted awake
742
+ po . recv( ) ; // We should get punted awake
746
743
}
747
744
#[ test] #[ should_fail] #[ ignore( cfg( windows) ) ]
748
745
fn test_spawn_linked_unsup_fail_down( ) { // parent fails; child fails
@@ -810,27 +807,25 @@ fn test_spawn_linked_sup_propagate_sibling() {
810
807
811
808
#[ test]
812
809
fn test_run_basic( ) {
813
- let po = oldcomm : : Port ( ) ;
814
- let ch = oldcomm:: Chan ( & po) ;
810
+ let ( po, ch) = stream :: < ( ) > ( ) ;
815
811
do task( ) . spawn {
816
- oldcomm : : send( ch , ( ) ) ;
812
+ ch . send( ( ) ) ;
817
813
}
818
- oldcomm :: recv( po ) ;
814
+ po . recv( ) ;
819
815
}
820
816
821
817
#[ test]
822
818
fn test_add_wrapper( ) {
823
- let po = oldcomm : : Port ( ) ;
824
- let ch = oldcomm:: Chan ( & po) ;
819
+ let ( po, ch) = stream :: < ( ) > ( ) ;
825
820
let b0 = task( ) ;
826
821
let b1 = do b0. add_wrapper |body| {
827
822
fn ~( move body) {
828
823
body( ) ;
829
- oldcomm :: send( ch , ( ) ) ;
824
+ ch . send( ( ) ) ;
830
825
}
831
826
} ;
832
827
do b1. spawn { }
833
- oldcomm :: recv( po ) ;
828
+ po . recv( ) ;
834
829
}
835
830
836
831
#[ test]
@@ -883,32 +878,31 @@ fn test_spawn_sched_no_threads() {
883
878
884
879
#[ test]
885
880
fn test_spawn_sched( ) {
886
- let po = oldcomm : : Port ( ) ;
887
- let ch = oldcomm :: Chan ( & po ) ;
881
+ let ( po , ch ) = stream :: < ( ) > ( ) ;
882
+ let ch = SharedChan ( ch ) ;
888
883
889
- fn f( i: int, ch: oldcomm :: Chan < ( ) > ) {
884
+ fn f( i: int, ch: SharedChan < ( ) > ) {
890
885
let parent_sched_id = rt:: rust_get_sched_id( ) ;
891
886
892
887
do spawn_sched( SingleThreaded ) {
893
888
let child_sched_id = rt:: rust_get_sched_id( ) ;
894
889
assert parent_sched_id != child_sched_id;
895
890
896
891
if ( i == 0 ) {
897
- oldcomm :: send( ch , ( ) ) ;
892
+ ch . send( ( ) ) ;
898
893
} else {
899
- f( i - 1 , ch) ;
894
+ f( i - 1 , ch. clone ( ) ) ;
900
895
}
901
896
} ;
902
897
903
898
}
904
899
f( 10 , ch) ;
905
- oldcomm :: recv( po ) ;
900
+ po . recv( ) ;
906
901
}
907
902
908
903
#[ test]
909
904
fn test_spawn_sched_childs_on_default_sched( ) {
910
- let po = oldcomm : : Port ( ) ;
911
- let ch = oldcomm:: Chan ( & po) ;
905
+ let ( po, ch) = stream( ) ;
912
906
913
907
// Assuming tests run on the default scheduler
914
908
let default_id = rt:: rust_get_sched_id( ) ;
@@ -919,11 +913,11 @@ fn test_spawn_sched_childs_on_default_sched() {
919
913
let child_sched_id = rt : : rust_get_sched_id( ) ;
920
914
assert parent_sched_id != child_sched_id;
921
915
assert child_sched_id == default_id;
922
- oldcomm :: send( ch , ( ) ) ;
916
+ ch . send( ( ) ) ;
923
917
} ;
924
918
} ;
925
919
926
- oldcomm :: recv( po ) ;
920
+ po . recv( ) ;
927
921
}
928
922
929
923
#[ nolink]
@@ -945,74 +939,69 @@ fn test_spawn_sched_blocking() {
945
939
// without affecting other schedulers
946
940
for iter:: repeat( 20 u) {
947
941
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( ) ;
952
944
953
945
let lock = testrt:: rust_dbg_lock_create( ) ;
954
946
955
947
do spawn_sched( SingleThreaded ) {
956
948
unsafe {
957
949
testrt:: rust_dbg_lock_lock( lock) ;
958
950
959
- oldcomm :: send( start_ch , ( ) ) ;
951
+ start_ch . send( ( ) ) ;
960
952
961
953
// Block the scheduler thread
962
954
testrt:: rust_dbg_lock_wait( lock) ;
963
955
testrt:: rust_dbg_lock_unlock( lock) ;
964
956
965
- oldcomm :: send( fin_ch , ( ) ) ;
957
+ fin_ch . send( ( ) ) ;
966
958
}
967
959
} ;
968
960
969
961
// Wait until the other task has its lock
970
- oldcomm :: recv( start_po ) ;
962
+ start_po . recv( ) ;
971
963
972
- fn pingpong( po: oldcomm :: Port < int > , ch: oldcomm :: Chan < int > ) {
964
+ fn pingpong( po: & Port < int > , ch: & Chan < int > ) {
973
965
let mut val = 20 ;
974
966
while val > 0 {
975
- val = oldcomm :: recv( po ) ;
976
- oldcomm :: send( ch , val - 1 ) ;
967
+ val = po . recv( ) ;
968
+ ch . send( val - 1 ) ;
977
969
}
978
970
}
979
971
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( ) ;
984
974
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) ;
988
978
} ;
989
979
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) ;
993
983
testrt:: rust_dbg_lock_lock( lock) ;
994
984
testrt:: rust_dbg_lock_signal( lock) ;
995
985
testrt:: rust_dbg_lock_unlock( lock) ;
996
- oldcomm :: recv( fin_po ) ;
986
+ fin_po . recv( ) ;
997
987
testrt:: rust_dbg_lock_destroy( lock) ;
998
988
}
999
989
}
1000
990
}
1001
991
1002
992
#[ cfg( test) ]
1003
993
fn 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 > ( ) ;
1006
995
1007
996
let x = ~1 ;
1008
997
let x_in_parent = ptr:: addr_of( & ( * x) ) as uint;
1009
998
1010
999
do spawnfn |move x| {
1011
1000
let x_in_child = ptr:: addr_of( & ( * x) ) as uint;
1012
- oldcomm :: send( ch , x_in_child) ;
1001
+ ch . send( x_in_child) ;
1013
1002
}
1014
1003
1015
- let x_in_child = oldcomm :: recv( p ) ;
1004
+ let x_in_child = p . recv( ) ;
1016
1005
assert x_in_parent == x_in_child;
1017
1006
}
1018
1007
@@ -1050,20 +1039,18 @@ fn test_avoid_copying_the_body_unlinked() {
1050
1039
1051
1040
#[ test]
1052
1041
fn test_platform_thread( ) {
1053
- let po = oldcomm : : Port ( ) ;
1054
- let ch = oldcomm:: Chan ( & po) ;
1042
+ let ( po, ch) = stream( ) ;
1055
1043
do task( ) . sched_mode( PlatformThread ) . spawn {
1056
- oldcomm : : send( ch , ( ) ) ;
1044
+ ch . send( ( ) ) ;
1057
1045
}
1058
- oldcomm :: recv( po ) ;
1046
+ po . recv( ) ;
1059
1047
}
1060
1048
1061
1049
#[ test]
1062
1050
#[ ignore( cfg( windows) ) ]
1063
1051
#[ should_fail]
1064
1052
fn test_unkillable( ) {
1065
- let po = oldcomm : : Port ( ) ;
1066
- let ch = po. chan( ) ;
1053
+ let ( po, ch) = stream( ) ;
1067
1054
1068
1055
// We want to do this after failing
1069
1056
do spawn_unlinked {
0 commit comments