Annotation of embedaddon/bird/sysdep/unix/timer.h, revision 1.1.1.2
1.1 misho 1: /*
2: * BIRD -- Unix Timers
3: *
4: * (c) 1998 Martin Mares <mj@ucw.cz>
5: *
6: * Can be freely distributed and used under the terms of the GNU GPL.
7: */
8:
9: #ifndef _BIRD_TIMER_H_
10: #define _BIRD_TIMER_H_
11:
12: #include <time.h>
13:
14: #include "lib/resource.h"
15:
16: typedef time_t bird_clock_t; /* Use instead of time_t */
17:
18: typedef struct timer {
19: resource r;
20: void (*hook)(struct timer *);
21: void *data;
1.1.1.2 ! misho 22: uint randomize; /* Amount of randomization */
! 23: uint recurrent; /* Timer recurrence */
1.1 misho 24: node n; /* Internal link */
25: bird_clock_t expires; /* 0=inactive */
26: } timer;
27:
28: timer *tm_new(pool *);
1.1.1.2 ! misho 29: void tm_start(timer *, uint after);
1.1 misho 30: void tm_stop(timer *);
31: void tm_dump_all(void);
32:
33: extern bird_clock_t now; /* Relative, monotonic time in seconds */
34: extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */
35: extern bird_clock_t boot_time;
36:
37: static inline int
38: tm_active(timer *t)
39: {
40: return t->expires != 0;
41: }
42:
43: static inline bird_clock_t
44: tm_remains(timer *t)
45: {
46: return t->expires ? t->expires - now : 0;
47: }
48:
49: static inline void
1.1.1.2 ! misho 50: tm_start_max(timer *t, bird_clock_t after)
1.1 misho 51: {
52: bird_clock_t rem = tm_remains(t);
53: tm_start(t, (rem > after) ? rem : after);
54: }
55:
56: static inline timer *
1.1.1.2 ! misho 57: tm_new_set(pool *p, void (*hook)(struct timer *), void *data, uint rand, uint rec)
1.1 misho 58: {
59: timer *t = tm_new(p);
60: t->hook = hook;
61: t->data = data;
62: t->randomize = rand;
63: t->recurrent = rec;
64: return t;
65: }
66:
67:
68: struct timeformat {
69: char *fmt1, *fmt2;
70: bird_clock_t limit;
71: };
72:
73: bird_clock_t tm_parse_date(char *); /* Convert date to bird_clock_t */
74: bird_clock_t tm_parse_datetime(char *); /* Convert date to bird_clock_t */
75:
76: #define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_datetime */
77:
1.1.1.2 ! misho 78: void tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t);
! 79: int tm_format_real_time(char *x, size_t max, const char *fmt, bird_clock_t t);
! 80:
! 81: #define TIME_T_IS_64BIT (sizeof(time_t) == 8)
! 82: #define TIME_T_IS_SIGNED ((time_t) -1 < 0)
! 83:
! 84: #define TIME_INFINITY \
! 85: ((time_t) (TIME_T_IS_SIGNED ? \
! 86: (TIME_T_IS_64BIT ? 0x7fffffffffffffff : 0x7fffffff): \
! 87: (TIME_T_IS_64BIT ? 0xffffffffffffffff : 0xffffffff)))
1.1 misho 88:
89: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>