/* Add timer event thread. */ struct thread * thread_add_timer_timeval (struct lib_globals *zg, int (*func) (struct thread *), void *arg, struct pal_timeval timer) { struct thread_master *m = zg->master; struct pal_timeval timer_now; struct thread *thread; pal_assert (m != NULL); thread = thread_get (zg, THREAD_TIMER, func, arg); if (thread == NULL) return NULL; /* Do we need jitter here? */ pal_time_tzcurrent (&timer_now, NULL); timer_now.tv_sec += timer.tv_sec; timer_now.tv_usec += timer.tv_usec; while (timer_now.tv_usec >= TV_USEC_PER_SEC) { timer_now.tv_sec++; timer_now.tv_usec -= TV_USEC_PER_SEC; } /* Correct negative value. */ if (timer_now.tv_sec < 0) timer_now.tv_sec = PAL_TIME_MAX_TV_SEC; if (timer_now.tv_usec < 0) timer_now.tv_usec = PAL_TIME_MAX_TV_USEC; thread->u.sands = timer_now; /* Common process. */ thread_add_timer_common (m, thread); return thread; }
/* Add timer event thread. */ struct thread * thread_add_timer (struct lib_globals *zg, int (*func) (struct thread *), void *arg, long timer) { struct thread_master *m = zg->master; struct pal_timeval timer_now; struct thread *thread; pal_assert (m != NULL); thread = thread_get (zg, THREAD_TIMER, func, arg); if (thread == NULL) return NULL; pal_time_tzcurrent (&timer_now, NULL); timer_now.tv_sec += timer; thread->u.sands = timer_now; /* Common process. */ thread_add_timer_common (m, thread); return thread; }
/* Add timer event thread. */ struct thread * thread_add_timer (struct thread_master *master, int (*func) (struct thread *), void *arg, long timer) { struct thread_master *m = master; struct pal_timeval timer_now; struct thread *thread; assert (m != NULL); thread = thread_get (m, THREAD_TIMER, func, arg); if (thread == NULL) return NULL; /* Do we need jitter here? */ pal_time_tzcurrent (&timer_now, NULL); timer_now.tv_sec += timer; thread->u.sands = timer_now; /* Common process. */ thread_add_timer_common (m, thread); return thread; }