@@ -287,10 +287,25 @@ impl<H: Handler> EventLoop<H> {
287287 for evt in events {
288288 match evt. token ( ) {
289289 NOTIFY_OR_TIMER => {
290- // channel and timer use the same token, so we need to
291- // check both the channel and the timer
292- self . notify ( handler) ;
293- self . timer_process ( handler) ;
290+ while self . notify_queue . len ( ) > 0 {
291+ match self . notify_queue . pop ( ) {
292+ Some ( id) if id == self . channel_noti_id => {
293+ self . notify ( handler) ;
294+ }
295+ Some ( id) if id == self . timer_noti_id => {
296+ self . timer_process ( handler) ;
297+ }
298+ Some ( id) => {
299+ trace ! ( "event loop got spurious wakeup for unknown id: {:?}" , id) ;
300+ }
301+ None => {
302+ // Spurious wakeup, nothing to do
303+ trace ! (
304+ "event loop got spurious wakeup with no id"
305+ ) ;
306+ }
307+ }
308+ }
294309 }
295310 _ => self . io_event ( handler, evt) ,
296311 }
@@ -302,21 +317,17 @@ impl<H: Handler> EventLoop<H> {
302317 }
303318
304319 fn notify ( & mut self , handler : & mut H ) {
305- for _ in 0 ..self . config . messages_per_tick {
306- match self . notify_rx . try_recv ( ) {
307- Ok ( msg) => {
308- handler. notify ( self , msg) ;
309- let _ = self . notify_queue . pop ( ) ;
310- }
311- _ => break ,
320+ match self . notify_rx . try_recv ( ) {
321+ Ok ( msg) => {
322+ handler. notify ( self , msg) ;
312323 }
324+ _ => { }
313325 }
314326 }
315327
316328 fn timer_process ( & mut self , handler : & mut H ) {
317329 while let Some ( t) = self . timer . poll ( ) {
318330 handler. timeout ( self , t) ;
319- let _ = self . notify_queue . pop ( ) ;
320331 }
321332 }
322333}
0 commit comments