MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / run_timer_process_jif

Function run_timer_process_jif

timer.c:619–698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617}
618
619static void run_timer_process_jif(void)
620{
621 unsigned int multiple;
622 unsigned int umultiple;
623 unsigned int cnt;
624 unsigned int ucnt;
625 struct timeval o_tv;
626 struct timeval tv;
627 struct timeval sync_ts, last_ts;
628 stime_t interval, drift;
629 utime_t last_ticks, last_sync = 0;
630
631 o_tv.tv_sec = 0;
632 o_tv.tv_usec = ITIMER_TICK; /* internal timer */
633 multiple = ((TIMER_TICK*1000000)) / (UTIMER_TICK);
634 umultiple = (UTIMER_TICK) / (ITIMER_TICK);
635
636 LM_DBG("tv = %ld, %ld, m=%d, mu=%d\n",
637 (long)o_tv.tv_sec,(long)o_tv.tv_usec,multiple,umultiple);
638
639 gettimeofday(&last_ts, 0);
640 last_ticks = *ijiffies;
641
642 for( cnt=1,ucnt=1 ; ; ucnt++ ) {
643 tv = o_tv;
644 select( 0, 0, 0, 0, &tv);
645
646 /* update internal timer */
647 *(ijiffies)+=ITIMER_TICK;
648
649 /* update public utimer */
650 if (ucnt==umultiple) {
651 *(ujiffies)+=UTIMER_TICK;
652 /* no overflow test as even if we go for 1 microsecond tick,
653 * this will happen in 14038618 years :P */
654 ucnt = 0;
655
656 cnt++;
657 /* update public timer */
658 if (cnt==multiple) {
659 *(jiffies)+=TIMER_TICK;
660 /* test for overflow (if tick= 1s =>overflow in 136 years)*/
661 cnt = 0;
662 }
663 }
664
665 /* synchronize with system time if needed */
666 if (*ijiffies - last_sync >= TIMER_SYNC_TICKS) {
667 last_sync = *ijiffies;
668
669 gettimeofday(&sync_ts, 0);
670 interval = (utime_t)sync_ts.tv_sec*1000000 + sync_ts.tv_usec
671 - (utime_t)last_ts.tv_sec*1000000 - last_ts.tv_usec;
672
673 drift = interval - (*ijiffies - last_ticks);
674
675 /* protect against sudden time changes */
676 if (interval < 0 || drift < 0 || drift > TIMER_SYNC_TICKS) {

Callers 1

start_timer_processesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected