diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2013-09-16 23:57:40 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2013-09-16 23:57:40 +0200 |
commit | 6a8d3f1c1ffbd964e4d11b452c73e1ea70310af3 (patch) | |
tree | ffad2ba5c281d87ec64f3b9f419b17251ef616a6 /proto/bfd/io.h | |
parent | bf139664aa2ae9956b520ba4813bb6e03bf1a3e8 (diff) |
BFD work in progress.
Now it compiles and mostly works.
Diffstat (limited to 'proto/bfd/io.h')
-rw-r--r-- | proto/bfd/io.h | 70 |
1 files changed, 53 insertions, 17 deletions
diff --git a/proto/bfd/io.h b/proto/bfd/io.h index 7fc45194..c186ba2b 100644 --- a/proto/bfd/io.h +++ b/proto/bfd/io.h @@ -1,44 +1,69 @@ +/* + * BIRD -- I/O and event loop + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ -typedef s64 xxx_time; +#ifndef _BIRD_BFD_IO_H_ +#define _BIRD_BFD_IO_H_ -typedef struct timer +#include "nest/bird.h" +#include "lib/lists.h" +#include "lib/resource.h" +#include "lib/event.h" +#include "lib/socket.h" +// #include "lib/timer.h" + + +#define S *1000000 +#define MS *1000 +#define US *1 +#define TO_S /1000000 +#define TO_MS /1000 +#define TO_US /1 + + +typedef s64 btime; + +typedef struct timer2 { resource r; void (*hook)(struct timer2 *); void *data; - xxx_time expires; /* 0=inactive */ - unsigned randomize; /* Amount of randomization */ - unsigned recurrent; /* Timer recurrence */ + btime expires; /* 0=inactive */ + uint randomize; /* Amount of randomization */ + uint recurrent; /* Timer recurrence */ int index; -} timer; +} timer2; +btime current_time(void); void ev2_schedule(event *e); - timer2 *tm2_new(pool *p); -void tm2_start(timer2 *t, xxx_time after); +void tm2_set(timer2 *t, btime when); +void tm2_start(timer2 *t, btime after); void tm2_stop(timer2 *t); -static inline xxx_time -tm2_remains(timer2 *t) +static inline int +tm2_active(timer2 *t) { - return (t->expires > xxxnow) ? t->expires - xxxnow : 0; + return t->expires != 0; } -static inline void -tm2_start_max(timer2 *t, xxx_time after) +static inline btime +tm2_remains(timer2 *t) { - xxx_time rem = tm2_remains(t); - tm2_start(t, MAX(rem, after)); + btime now = current_time(); + return (t->expires > now) ? (t->expires - now) : 0; } static inline timer2 * -tm2_new_set(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand) +tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand) { timer2 *t = tm2_new(p); t->hook = hook; @@ -48,6 +73,14 @@ tm2_new_set(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint r return t; } +/* +static inline void +tm2_start_max(timer2 *t, btime after) +{ + btime rem = tm2_remains(t); + tm2_start(t, _MAX(rem, after)); +} +*/ void sk_start(sock *s); @@ -58,5 +91,8 @@ void sk_stop(sock *s); struct birdloop *birdloop_new(pool *p); void birdloop_enter(struct birdloop *loop); void birdloop_leave(struct birdloop *loop); -void birdloop_main(struct birdloop *loop); +void birdloop_mask_wakeups(struct birdloop *loop); +void birdloop_unmask_wakeups(struct birdloop *loop); + +#endif /* _BIRD_BFD_IO_H_ */ |