summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog4
-rw-r--r--lib/thread.c67
2 files changed, 37 insertions, 34 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 2bbda12b..5aedc1e2 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -3,6 +3,10 @@
* sockopt.{c,h}: add sockopt_iphdrincl_swab_{htosys,systoh},
functions to change byte order between system IP_HDRINCL order
and host order.
+ * thread.c: (funcname_thread_add_timer_timeval) new function, add
+ timer at specified timeval.
+ (funcname_thread_add_timer) use funcname_thread_add_timer_timeval.
+ (funcname_thread_add_timer_msec) ditto
2004-10-04 Hasso Tepper <hasso at quagga.net>
diff --git a/lib/thread.c b/lib/thread.c
index 2e953c55..474571e6 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -482,13 +482,15 @@ funcname_thread_add_write (struct thread_master *m,
return thread;
}
-/* Add timer event thread. */
-struct thread *
-funcname_thread_add_timer (struct thread_master *m,
- int (*func) (struct thread *), void *arg, long timer, char* funcname)
+static struct thread *
+funcname_thread_add_timer_timeval (struct thread_master *m,
+ int (*func) (struct thread *),
+ void *arg,
+ struct timeval *time_relative,
+ char* funcname)
{
- struct timeval timer_now;
struct thread *thread;
+ struct timeval timer_now;
#ifndef TIMER_NO_SORT
struct thread *tt;
#endif /* TIMER_NO_SORT */
@@ -499,7 +501,9 @@ funcname_thread_add_timer (struct thread_master *m,
/* Do we need jitter here? */
gettimeofday (&timer_now, NULL);
- timer_now.tv_sec += timer;
+ timer_now.tv_sec += time_relative->tv_sec;
+ timer_now.tv_usec += time_relative->tv_usec;
+ timeval_adjust (timer_now);
thread->u.sands = timer_now;
/* Sort by timeval. */
@@ -519,44 +523,39 @@ funcname_thread_add_timer (struct thread_master *m,
return thread;
}
-/* Add timer event thread with "millisecond" resolution */
+
+/* Add timer event thread. */
struct thread *
-funcname_thread_add_timer_msec (struct thread_master *m,
- int (*func) (struct thread *), void *arg, long timer, char* funcname)
+funcname_thread_add_timer (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 */
+ struct timeval trel;
assert (m != NULL);
- thread = thread_get (m, THREAD_TIMER, func, arg, funcname);
+ trel.tv_sec += timer;
+ trel.tv_usec = 0;
- timer = 1000*timer; /* milli -> micro */
+ return funcname_thread_add_timer_timeval (m, func, arg, &trel, funcname);
+}
- /* 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;
+/* 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 trel;
- /* 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;
+ assert (m != NULL);
- if (tt)
- thread_list_add_before (&m->timer, tt, thread);
- else
- thread_list_add (&m->timer, thread);
-#endif /* TIMER_NO_SORT */
+ timer = 1000*timer; /* milli -> micro */
- return thread;
+ trel.tv_sec += timer / TIMER_SECOND_MICRO;
+ trel.tv_usec += (timer % TIMER_SECOND_MICRO);
+
+ return funcname_thread_add_timer_timeval (m, func, arg, &trel, funcname);
}
/* Add simple event thread. */