99 ready,
1010 stream:: { Stream , StreamExt } ,
1111 sink:: Sink ,
12- task:: { Waker , Poll } ,
12+ task:: { Context , Poll } ,
1313 } ,
1414 futures_test:: task:: noop_waker_ref,
1515 std:: pin:: Pin ,
1818/// Single producer, single consumer
1919#[ bench]
2020fn unbounded_1_tx ( b : & mut Bencher ) {
21- let waker = noop_waker_ref ( ) ;
21+ let mut cx = Context :: from_waker ( noop_waker_ref ( ) ) ;
2222 b. iter ( || {
2323 let ( tx, mut rx) = mpsc:: unbounded ( ) ;
2424
@@ -27,20 +27,20 @@ fn unbounded_1_tx(b: &mut Bencher) {
2727 for i in 0 ..1000 {
2828
2929 // Poll, not ready, park
30- assert_eq ! ( Poll :: Pending , rx. poll_next_unpin( waker ) ) ;
30+ assert_eq ! ( Poll :: Pending , rx. poll_next_unpin( & mut cx ) ) ;
3131
3232 UnboundedSender :: unbounded_send ( & tx, i) . unwrap ( ) ;
3333
3434 // Now poll ready
35- assert_eq ! ( Poll :: Ready ( Some ( i) ) , rx. poll_next_unpin( waker ) ) ;
35+ assert_eq ! ( Poll :: Ready ( Some ( i) ) , rx. poll_next_unpin( & mut cx ) ) ;
3636 }
3737 } )
3838}
3939
4040/// 100 producers, single consumer
4141#[ bench]
4242fn unbounded_100_tx ( b : & mut Bencher ) {
43- let waker = noop_waker_ref ( ) ;
43+ let mut cx = Context :: from_waker ( noop_waker_ref ( ) ) ;
4444 b. iter ( || {
4545 let ( tx, mut rx) = mpsc:: unbounded ( ) ;
4646
@@ -49,26 +49,26 @@ fn unbounded_100_tx(b: &mut Bencher) {
4949 // 1000 send/recv operations total, result should be divided by 1000
5050 for _ in 0 ..10 {
5151 for i in 0 ..tx. len ( ) {
52- assert_eq ! ( Poll :: Pending , rx. poll_next_unpin( waker ) ) ;
52+ assert_eq ! ( Poll :: Pending , rx. poll_next_unpin( & mut cx ) ) ;
5353
5454 UnboundedSender :: unbounded_send ( & tx[ i] , i) . unwrap ( ) ;
5555
56- assert_eq ! ( Poll :: Ready ( Some ( i) ) , rx. poll_next_unpin( waker ) ) ;
56+ assert_eq ! ( Poll :: Ready ( Some ( i) ) , rx. poll_next_unpin( & mut cx ) ) ;
5757 }
5858 }
5959 } )
6060}
6161
6262#[ bench]
6363fn unbounded_uncontended ( b : & mut Bencher ) {
64- let waker = noop_waker_ref ( ) ;
64+ let mut cx = Context :: from_waker ( noop_waker_ref ( ) ) ;
6565 b. iter ( || {
6666 let ( tx, mut rx) = mpsc:: unbounded ( ) ;
6767
6868 for i in 0 ..1000 {
6969 UnboundedSender :: unbounded_send ( & tx, i) . expect ( "send" ) ;
7070 // No need to create a task, because poll is not going to park.
71- assert_eq ! ( Poll :: Ready ( Some ( i) ) , rx. poll_next_unpin( waker ) ) ;
71+ assert_eq ! ( Poll :: Ready ( Some ( i) ) , rx. poll_next_unpin( & mut cx ) ) ;
7272 }
7373 } )
7474}
@@ -84,41 +84,41 @@ struct TestSender {
8484impl Stream for TestSender {
8585 type Item = u32 ;
8686
87- fn poll_next ( mut self : Pin < & mut Self > , waker : & Waker )
87+ fn poll_next ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > )
8888 -> Poll < Option < Self :: Item > >
8989 {
9090 let this = & mut * self ;
9191 let mut tx = Pin :: new ( & mut this. tx ) ;
9292
93- ready ! ( tx. as_mut( ) . poll_ready( waker ) ) . unwrap ( ) ;
93+ ready ! ( tx. as_mut( ) . poll_ready( cx ) ) . unwrap ( ) ;
9494 tx. as_mut ( ) . start_send ( this. last + 1 ) . unwrap ( ) ;
9595 this. last += 1 ;
96- assert_eq ! ( Poll :: Ready ( Ok ( ( ) ) ) , tx. as_mut( ) . poll_flush( waker ) ) ;
96+ assert_eq ! ( Poll :: Ready ( Ok ( ( ) ) ) , tx. as_mut( ) . poll_flush( cx ) ) ;
9797 Poll :: Ready ( Some ( this. last ) )
9898 }
9999}
100100
101101/// Single producers, single consumer
102102#[ bench]
103103fn bounded_1_tx ( b : & mut Bencher ) {
104- let waker = noop_waker_ref ( ) ;
104+ let mut cx = Context :: from_waker ( noop_waker_ref ( ) ) ;
105105 b. iter ( || {
106106 let ( tx, mut rx) = mpsc:: channel ( 0 ) ;
107107
108108 let mut tx = TestSender { tx, last : 0 } ;
109109
110110 for i in 0 ..1000 {
111- assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , tx. poll_next_unpin( waker ) ) ;
112- assert_eq ! ( Poll :: Pending , tx. poll_next_unpin( waker ) ) ;
113- assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , rx. poll_next_unpin( waker ) ) ;
111+ assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , tx. poll_next_unpin( & mut cx ) ) ;
112+ assert_eq ! ( Poll :: Pending , tx. poll_next_unpin( & mut cx ) ) ;
113+ assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , rx. poll_next_unpin( & mut cx ) ) ;
114114 }
115115 } )
116116}
117117
118118/// 100 producers, single consumer
119119#[ bench]
120120fn bounded_100_tx ( b : & mut Bencher ) {
121- let waker = noop_waker_ref ( ) ;
121+ let mut cx = Context :: from_waker ( noop_waker_ref ( ) ) ;
122122 b. iter ( || {
123123 // Each sender can send one item after specified capacity
124124 let ( tx, mut rx) = mpsc:: channel ( 0 ) ;
@@ -133,11 +133,11 @@ fn bounded_100_tx(b: &mut Bencher) {
133133 for i in 0 ..10 {
134134 for j in 0 ..tx. len ( ) {
135135 // Send an item
136- assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , tx[ j] . poll_next_unpin( waker ) ) ;
136+ assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , tx[ j] . poll_next_unpin( & mut cx ) ) ;
137137 // Then block
138- assert_eq ! ( Poll :: Pending , tx[ j] . poll_next_unpin( waker ) ) ;
138+ assert_eq ! ( Poll :: Pending , tx[ j] . poll_next_unpin( & mut cx ) ) ;
139139 // Recv the item
140- assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , rx. poll_next_unpin( waker ) ) ;
140+ assert_eq ! ( Poll :: Ready ( Some ( i + 1 ) ) , rx. poll_next_unpin( & mut cx ) ) ;
141141 }
142142 }
143143 } )
0 commit comments