mirror of
				https://gitlab.labs.nic.cz/labs/bird.git
				synced 2024-05-11 16:54:54 +00:00 
			
		
		
		
	Timers: Integrate microsecond timers to the main loop
This commit is contained in:
		@@ -166,6 +166,8 @@ timers_init(struct timeloop *loop, pool *p)
 | 
				
			|||||||
  BUFFER_PUSH(loop->timers) = NULL;
 | 
					  BUFFER_PUSH(loop->timers) = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void io_log_event(void *hook, void *data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
timers_fire(struct timeloop *loop)
 | 
					timers_fire(struct timeloop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -195,6 +197,10 @@ timers_fire(struct timeloop *loop)
 | 
				
			|||||||
    else
 | 
					    else
 | 
				
			||||||
      tm2_stop(t);
 | 
					      tm2_stop(t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* This is ugly hack, we want to log just timers executed from the main I/O loop */
 | 
				
			||||||
 | 
					    if (loop == &main_timeloop)
 | 
				
			||||||
 | 
					      io_log_event(t->hook, t->data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    t->hook(t);
 | 
					    t->hook(t);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2507,9 +2507,10 @@ static int short_loops = 0;
 | 
				
			|||||||
void
 | 
					void
 | 
				
			||||||
io_loop(void)
 | 
					io_loop(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  int poll_tout;
 | 
					  int poll_tout, timeout;
 | 
				
			||||||
  time_t tout;
 | 
					  time_t tout;
 | 
				
			||||||
  int nfds, events, pout;
 | 
					  int nfds, events, pout;
 | 
				
			||||||
 | 
					  timer2 *t;
 | 
				
			||||||
  sock *s;
 | 
					  sock *s;
 | 
				
			||||||
  node *n;
 | 
					  node *n;
 | 
				
			||||||
  int fdmax = 256;
 | 
					  int fdmax = 256;
 | 
				
			||||||
@@ -2518,7 +2519,9 @@ io_loop(void)
 | 
				
			|||||||
  watchdog_start1();
 | 
					  watchdog_start1();
 | 
				
			||||||
  for(;;)
 | 
					  for(;;)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					      times_update(&main_timeloop);
 | 
				
			||||||
      events = ev_run_list(&global_event_list);
 | 
					      events = ev_run_list(&global_event_list);
 | 
				
			||||||
 | 
					      timers_fire(&main_timeloop);
 | 
				
			||||||
    timers:
 | 
					    timers:
 | 
				
			||||||
      update_times();
 | 
					      update_times();
 | 
				
			||||||
      tout = tm_first_shot();
 | 
					      tout = tm_first_shot();
 | 
				
			||||||
@@ -2527,10 +2530,16 @@ io_loop(void)
 | 
				
			|||||||
	  tm_shot();
 | 
						  tm_shot();
 | 
				
			||||||
	  goto timers;
 | 
						  goto timers;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
      poll_tout = (events ? 0 : MIN(tout - now, 3)) * 1000; /* Time in milliseconds */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      io_close_event();
 | 
					      io_close_event();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      poll_tout = (events ? 0 : MIN(tout - now, 3)) * 1000; /* Time in milliseconds */
 | 
				
			||||||
 | 
					      if (t = timers_first(&main_timeloop))
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
						times_update(&main_timeloop);
 | 
				
			||||||
 | 
						timeout = (tm2_remains(t) TO_MS) + 1;
 | 
				
			||||||
 | 
						poll_tout = MIN(poll_tout, timeout);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      nfds = 0;
 | 
					      nfds = 0;
 | 
				
			||||||
      WALK_LIST(n, sock_list)
 | 
					      WALK_LIST(n, sock_list)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -2601,6 +2610,8 @@ io_loop(void)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
      if (pout)
 | 
					      if (pout)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
						  times_update(&main_timeloop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	  /* guaranteed to be non-empty */
 | 
						  /* guaranteed to be non-empty */
 | 
				
			||||||
	  current_sock = SKIP_BACK(sock, n, HEAD(sock_list));
 | 
						  current_sock = SKIP_BACK(sock, n, HEAD(sock_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user