]> git.puffer.fish Git - mirror/frr.git/commitdiff
2004-10-05 Paul Jakma <paul@dishone.st>
authorpaul <paul>
Tue, 5 Oct 2004 14:57:50 +0000 (14:57 +0000)
committerpaul <paul>
Tue, 5 Oct 2004 14:57:50 +0000 (14:57 +0000)
* 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

lib/ChangeLog
lib/thread.c

index 2bbda12be3a949f263f6ec3f004844f5e581682e..5aedc1e27a1361cac42ff14afdfb849b4c670b1d 100644 (file)
@@ -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>
 
index 2e953c550f3f99ef21f945eac1bab03e00f23a57..474571e6d93cbfa712d3f1d4e998fe45ab62d483 100644 (file)
@@ -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. */