diff options
Diffstat (limited to 'lib/thread.c')
-rw-r--r-- | lib/thread.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/thread.c b/lib/thread.c index 402167cf..93809f2f 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -518,6 +518,46 @@ funcname_thread_add_timer (struct thread_master *m, return thread; } +/* Add timer event thread with "millisecond" resolution */ +struct thread * +funcname_thread_add_timer_msec (struct thread_master *m, + int (*func) (struct thread *), void *arg, long timer, char* funcname) +{ + struct timeval timer_now; + struct thread *thread; +#ifndef TIMER_NO_SORT + struct thread *tt; +#endif /* TIMER_NO_SORT */ + + assert (m != NULL); + + thread = thread_get (m, THREAD_TIMER, func, arg, funcname); + + timer = 1000*timer; /* milli -> micro */ + + /* Do we need jitter here? */ + gettimeofday (&timer_now, NULL); + timer_now.tv_sec += timer / TIMER_SECOND_MICRO; + timer_now.tv_usec += (timer % TIMER_SECOND_MICRO); + thread->u.sands = timer_now; + + /* Sort by timeval. */ +#ifdef TIMER_NO_SORT + thread_list_add (&m->timer, thread); +#else + for (tt = m->timer.head; tt; tt = tt->next) + if (timeval_cmp (thread->u.sands, tt->u.sands) <= 0) + break; + + if (tt) + thread_list_add_before (&m->timer, tt, thread); + else + thread_list_add (&m->timer, thread); +#endif /* TIMER_NO_SORT */ + + return thread; +} + /* Add simple event thread. */ struct thread * funcname_thread_add_event (struct thread_master *m, |