Commit a6f79ca5 authored by Ondrej Zajicek (work)'s avatar Ondrej Zajicek (work)
Browse files

Timers: Revert temporary names and remove old timer.h

parent 574b2324
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@
#include "lib/resource.h"
#include "lib/string.h"
#include "lib/event.h"
#include "sysdep/unix/timer.h"
#include "lib/timer.h"
#include "conf/conf.h"
#include "filter/filter.h"

@@ -341,9 +341,9 @@ config_commit(struct config *c, int type, uint timeout)

  undo_available = 1;
  if (timeout)
    tm2_start(config_timer, timeout S);
    tm_start(config_timer, timeout S);
  else
    tm2_stop(config_timer);
    tm_stop(config_timer);

  if (configuring)
    {
@@ -384,7 +384,7 @@ config_confirm(void)
  if (config_timer->expires == 0)
    return CONF_NOTHING;

  tm2_stop(config_timer);
  tm_stop(config_timer);

  return CONF_CONFIRM;
}
@@ -420,7 +420,7 @@ config_undo(void)
    return CONF_NOTHING;

  undo_available = 0;
  tm2_stop(config_timer);
  tm_stop(config_timer);

  if (configuring)
    {
@@ -468,7 +468,7 @@ config_init(void)
  config_event = ev_new(&root_pool);
  config_event->hook = config_done;

  config_timer = tm2_new(&root_pool);
  config_timer = tm_new(&root_pool);
  config_timer->hook = config_timeout;
}

+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#include "lib/ip.h"
#include "lib/hash.h"
#include "lib/resource.h"
#include "sysdep/unix/timer.h"
#include "lib/timer.h"


/* Configuration structure */
+0 −10
Original line number Diff line number Diff line
@@ -11,16 +11,6 @@ CF_HDR
#define PARSER 1

#include "nest/bird.h"
#include "conf/conf.h"
#include "lib/resource.h"
#include "lib/socket.h"
#include "sysdep/unix/timer.h"
#include "lib/string.h"
#include "nest/protocol.h"
#include "nest/iface.h"
#include "nest/route.h"
#include "nest/cli.h"
#include "filter/filter.h"
#include "lib/flowspec.h"


+23 −23
Original line number Diff line number Diff line
@@ -93,17 +93,17 @@ current_real_time(void)


static void
tm2_free(resource *r)
tm_free(resource *r)
{
  timer2 *t = (timer2 *) r;
  timer *t = (void *) r;

  tm2_stop(t);
  tm_stop(t);
}

static void
tm2_dump(resource *r)
tm_dump(resource *r)
{
  timer2 *t = (timer2 *) r;
  timer *t = (void *) r;

  debug("(code %p, data %p, ", t->hook, t->data);
  if (t->randomize)
@@ -117,25 +117,25 @@ tm2_dump(resource *r)
}


static struct resclass tm2_class = {
static struct resclass tm_class = {
  "Timer",
  sizeof(timer2),
  tm2_free,
  tm2_dump,
  sizeof(timer),
  tm_free,
  tm_dump,
  NULL,
  NULL
};

timer2 *
tm2_new(pool *p)
timer *
tm_new(pool *p)
{
  timer2 *t = ralloc(p, &tm2_class);
  timer *t = ralloc(p, &tm_class);
  t->index = -1;
  return t;
}

void
tm2_set(timer2 *t, btime when)
tm_set(timer *t, btime when)
{
  struct timeloop *loop = timeloop_current();
  uint tc = timers_count(loop);
@@ -145,17 +145,17 @@ tm2_set(timer2 *t, btime when)
    t->index = ++tc;
    t->expires = when;
    BUFFER_PUSH(loop->timers) = t;
    HEAP_INSERT(loop->timers.data, tc, timer2 *, TIMER_LESS, TIMER_SWAP);
    HEAP_INSERT(loop->timers.data, tc, timer *, TIMER_LESS, TIMER_SWAP);
  }
  else if (t->expires < when)
  {
    t->expires = when;
    HEAP_INCREASE(loop->timers.data, tc, timer2 *, TIMER_LESS, TIMER_SWAP, t->index);
    HEAP_INCREASE(loop->timers.data, tc, timer *, TIMER_LESS, TIMER_SWAP, t->index);
  }
  else if (t->expires > when)
  {
    t->expires = when;
    HEAP_DECREASE(loop->timers.data, tc, timer2 *, TIMER_LESS, TIMER_SWAP, t->index);
    HEAP_DECREASE(loop->timers.data, tc, timer *, TIMER_LESS, TIMER_SWAP, t->index);
  }

#ifdef CONFIG_BFD
@@ -166,13 +166,13 @@ tm2_set(timer2 *t, btime when)
}

void
tm2_start(timer2 *t, btime after)
tm_start(timer *t, btime after)
{
  tm2_set(t, current_time() + MAX(after, 0));
  tm_set(t, current_time() + MAX(after, 0));
}

void
tm2_stop(timer2 *t)
tm_stop(timer *t)
{
  if (!t->expires)
    return;
@@ -180,7 +180,7 @@ tm2_stop(timer2 *t)
  struct timeloop *loop = timeloop_current();
  uint tc = timers_count(loop);

  HEAP_DELETE(loop->timers.data, tc, timer2 *, TIMER_LESS, TIMER_SWAP, t->index);
  HEAP_DELETE(loop->timers.data, tc, timer *, TIMER_LESS, TIMER_SWAP, t->index);
  BUFFER_POP(loop->timers);

  t->index = -1;
@@ -202,7 +202,7 @@ void
timers_fire(struct timeloop *loop)
{
  btime base_time;
  timer2 *t;
  timer *t;

  times_update(loop);
  base_time = loop->last_time;
@@ -222,10 +222,10 @@ timers_fire(struct timeloop *loop)
      if (t->randomize)
	when += random() % (t->randomize + 1);

      tm2_set(t, when);
      tm_set(t, when);
    }
    else
      tm2_stop(t);
      tm_stop(t);

    /* This is ugly hack, we want to log just timers executed from the main I/O loop */
    if (loop == &main_timeloop)
+21 −21
Original line number Diff line number Diff line
@@ -7,18 +7,18 @@
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#ifndef _BIRD_TIMER2_H_
#define _BIRD_TIMER2_H_
#ifndef _BIRD_TIMER_H_
#define _BIRD_TIMER_H_

#include "nest/bird.h"
#include "lib/buffer.h"
#include "lib/resource.h"


typedef struct timer2
typedef struct timer
{
  resource r;
  void (*hook)(struct timer2 *);
  void (*hook)(struct timer *);
  void *data;

  btime expires;			/* 0=inactive */
@@ -26,11 +26,11 @@ typedef struct timer2
  uint recurrent;			/* Timer recurrence */

  int index;
} timer2;
} timer;

struct timeloop
{
  BUFFER(timer2 *) timers;
  BUFFER(timer *) timers;
  btime last_time;
  btime real_time;
};
@@ -38,7 +38,7 @@ struct timeloop
static inline uint timers_count(struct timeloop *loop)
{ return loop->timers.used - 1; }

static inline timer2 *timers_first(struct timeloop *loop)
static inline timer *timers_first(struct timeloop *loop)
{ return (loop->timers.used > 1) ? loop->timers.data[1] : NULL; }

extern struct timeloop main_timeloop;
@@ -50,28 +50,28 @@ btime current_real_time(void);
//#define now_real (current_real_time() TO_S)
extern btime boot_time;

timer2 *tm2_new(pool *p);
void tm2_set(timer2 *t, btime when);
void tm2_start(timer2 *t, btime after);
void tm2_stop(timer2 *t);
timer *tm_new(pool *p);
void tm_set(timer *t, btime when);
void tm_start(timer *t, btime after);
void tm_stop(timer *t);

static inline int
tm2_active(timer2 *t)
tm_active(timer *t)
{
  return t->expires != 0;
}

static inline btime
tm2_remains(timer2 *t)
tm_remains(timer *t)
{
  btime now_ = current_time();
  return (t->expires > now_) ? (t->expires - now_) : 0;
}

static inline timer2 *
tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand)
static inline timer *
tm_new_init(pool *p, void (*hook)(struct timer *), void *data, uint rec, uint rand)
{
  timer2 *t = tm2_new(p);
  timer *t = tm_new(p);
  t->hook = hook;
  t->data = data;
  t->recurrent = rec;
@@ -80,17 +80,17 @@ tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint
}

static inline void
tm2_set_max(timer2 *t, btime when)
tm_set_max(timer *t, btime when)
{
  if (when > t->expires)
    tm2_set(t, when);
    tm_set(t, when);
}

static inline void
tm2_start_max(timer2 *t, btime after)
tm_start_max(timer *t, btime after)
{
  btime rem = tm2_remains(t);
  tm2_start(t, MAX_(rem, after));
  btime rem = tm_remains(t);
  tm_start(t, MAX_(rem, after));
}

/* In sysdep code */
Loading