1+ use super :: TRACE_START_INSTANT ;
12use crate :: cells:: bandwidth:: queue:: PacketQueue ;
23use crate :: cells:: { Cell , Packet } ;
3- use crate :: core:: CALIBRATED_START_INSTANT ;
44use crate :: error:: Error ;
55use crate :: metal:: timer:: Timer ;
66use async_trait:: async_trait;
@@ -148,23 +148,7 @@ where
148148{
149149 async fn dequeue ( & mut self ) -> Option < P > {
150150 // Wait for Start notify if not started yet
151- if !self . started {
152- if let Some ( notify_rx) = & mut self . notify_rx {
153- match notify_rx. recv ( ) . await {
154- Ok ( crate :: control:: RattanNotify :: Start ) => {
155- self . change_state ( 2 ) ;
156- self . started = true ;
157- }
158- Ok ( crate :: control:: RattanNotify :: FirstPacket ) => {
159- // Continue waiting for Start notify
160- }
161- Err ( _) => {
162- // Notify channel closed, exit
163- return None ;
164- }
165- }
166- }
167- }
151+ crate :: wait_until_started!( self , Start ) ;
168152
169153 // wait until next_available
170154 loop {
@@ -517,25 +501,11 @@ where
517501 Q : PacketQueue < P > ,
518502{
519503 async fn dequeue ( & mut self ) -> Option < P > {
520- // Wait for Start notify if not started yet
521- if !self . started {
522- if let Some ( notify_rx) = & mut self . notify_rx {
523- match notify_rx. recv ( ) . await {
524- Ok ( crate :: control:: RattanNotify :: Start ) => {
525- self . reset ( ) ;
526- self . change_state ( 2 ) ;
527- self . started = true ;
528- }
529- Ok ( crate :: control:: RattanNotify :: FirstPacket ) => {
530- // Continue waiting for Start notify
531- }
532- Err ( _) => {
533- // Notify channel closed, exit
534- return None ;
535- }
536- }
537- }
538- }
504+ // Wait for FirstPacket notify if not started yet
505+ #[ cfg( feature = "first-packet" ) ]
506+ crate :: wait_until_started!( self , FirstPacket ) ;
507+ #[ cfg( not( feature = "first-packet" ) ) ]
508+ crate :: wait_until_started!( self , Start ) ;
539509
540510 // wait until next_available
541511 loop {
@@ -551,7 +521,7 @@ where
551521 return None ;
552522 }
553523 }
554- recv_packet = self . egress. recv( ) => {
524+ recv_packet = self . egress. recv( ) => {
555525 match recv_packet {
556526 Some ( new_packet) => {
557527 match self . state. load( std:: sync:: atomic:: Ordering :: Acquire ) {
@@ -633,8 +603,8 @@ where
633603
634604 // This must be called before any dequeue
635605 fn reset ( & mut self ) {
636- self . next_available = * CALIBRATED_START_INSTANT . get_or_init ( Instant :: now) ;
637- self . next_change = * CALIBRATED_START_INSTANT . get_or_init ( Instant :: now) ;
606+ self . next_available = * TRACE_START_INSTANT . get_or_init ( Instant :: now) ;
607+ self . next_change = * TRACE_START_INSTANT . get_or_init ( Instant :: now) ;
638608 }
639609
640610 fn change_state ( & self , state : i32 ) {
0 commit comments