@@ -273,6 +273,7 @@ void pf_scheduler_init (pnet_t * net, uint32_t tick_interval)
273
273
274
274
net -> scheduler_timeout_first = PF_MAX_TIMEOUTS ; /* Nothing in queue */
275
275
net -> scheduler_timeout_free = PF_MAX_TIMEOUTS ; /* Nothing in queue. */
276
+ net -> scheduler_previous_time = os_get_current_time_us ();
276
277
277
278
if (net -> scheduler_timeout_mutex == NULL )
278
279
{
@@ -443,20 +444,40 @@ void pf_scheduler_remove (pnet_t * net, pf_scheduler_handle_t * handle)
443
444
void pf_scheduler_tick (pnet_t * net )
444
445
{
445
446
uint32_t ix ;
447
+ uint32_t when ;
446
448
pf_scheduler_timeout_ftn_t ftn ;
447
449
void * arg ;
448
450
uint32_t pf_current_time = os_get_current_time_us ();
451
+ uint32_t pf_previous_time = net -> scheduler_previous_time ;
452
+ net -> scheduler_previous_time = pf_current_time ;
449
453
450
454
os_mutex_lock (net -> scheduler_timeout_mutex );
451
455
452
456
/* Send event to all expired delay entries. */
453
- while ((net -> scheduler_timeout_first < PF_MAX_TIMEOUTS ) &&
454
- ((int32_t ) (
455
- pf_current_time -
456
- net -> scheduler_timeouts [net -> scheduler_timeout_first ].when ) >= 0 ))
457
+ while (net -> scheduler_timeout_first < PF_MAX_TIMEOUTS )
457
458
{
458
- /* Unlink from busy list */
459
459
ix = net -> scheduler_timeout_first ;
460
+ when = net -> scheduler_timeouts [ix ].when ;
461
+
462
+ /* Exit loop if not yet expired */
463
+ if (pf_current_time < when ) {
464
+ if (pf_previous_time <= pf_current_time ) {
465
+ /* Most common case; |--------PCW--------| */
466
+ break ;
467
+ } else if (pf_previous_time > when ) {
468
+ /* Overflow of both current time and when; |CW----------------P| */
469
+ break ;
470
+ }
471
+ /* Else overflow of current time; |C-----------------PW| */
472
+ } else if (
473
+ pf_current_time > when &&
474
+ pf_previous_time > when &&
475
+ pf_previous_time <= pf_current_time ) {
476
+ /* Overflow of when; |W-----------------PC| */
477
+ break ;
478
+ }
479
+
480
+ /* Unlink from busy list */
460
481
pf_scheduler_unlink (net , & net -> scheduler_timeout_first , ix );
461
482
462
483
ftn = net -> scheduler_timeouts [ix ].cb ;
0 commit comments