void update_timer_queue() { struct timeval delay_time; u_int64_t currtime; u_int64_t remainder, numerator; delay_time.tv_sec = 0; delay_time.tv_usec = 0; /* lock Read */ timer_read_lock(); if (timer_queue == NULL) { // No event to set timer for //delay_time.tv_sec = 0; //delay_time.tv_usec = 0; //del_timer(&aodv_timer); timer_read_unlock(); return; } //* Get the first time value currtime = getcurrtime(); if (time_before((unsigned long) timer_queue->time, (unsigned long) currtime)) { // If the event has allready happend, set the timeout to 1 microsecond :-) delay_time.tv_sec = 0; delay_time.tv_usec = 1; } else { // Set the timer to the actual seconds / microseconds from now //This is a fix for an error that occurs on ARM Linux Kernels because they do 64bits differently //Thanks to S. Peter Li for coming up with this fix! numerator = (timer_queue->time - currtime); remainder = (u_int64_t)do_div(numerator, 1000); delay_time.tv_sec = numerator; delay_time.tv_usec = remainder * 1000; } mod_timer(&aodv_timer, jiffies + tvtojiffies(&delay_time)); /* lock Read */ timer_read_unlock(); // Set the timer (in real time) return; }
int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue) { register unsigned long i, j; int k; i = tvtojiffies(&value->it_interval); j = tvtojiffies(&value->it_value); if (ovalue && (k = do_getitimer(which, ovalue)) < 0) return k; switch (which) { case ITIMER_REAL: del_timer_sync(¤t->real_timer); current->it_real_value = j; current->it_real_incr = i; if (!j) break; if (j > (unsigned long) LONG_MAX) j = LONG_MAX; i = j + jiffies; current->real_timer.expires = i; add_timer(¤t->real_timer); break; case ITIMER_VIRTUAL: if (j) j++; current->it_virt_value = j; current->it_virt_incr = i; break; case ITIMER_PROF: if (j) j++; current->it_prof_value = j; current->it_prof_incr = i; break; default: return -EINVAL; } return 0; }