]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/timer.h
4 * (c) 2013--2017 Ondrej Zajicek <santiago@crfreenet.org>
5 * (c) 2013--2017 CZ.NIC z.s.p.o.
7 * Can be freely distributed and used under the terms of the GNU GPL.
10 #ifndef _BIRD_TIMER_H_
11 #define _BIRD_TIMER_H_
13 #include "nest/bird.h"
14 #include "lib/buffer.h"
15 #include "lib/resource.h"
21 void (*hook
)(struct timer
*);
24 btime expires
; /* 0=inactive */
25 uint randomize
; /* Amount of randomization */
26 uint recurrent
; /* Timer recurrence */
33 BUFFER_(timer
*) timers
;
38 static inline uint
timers_count(struct timeloop
*loop
)
39 { return loop
->timers
.used
- 1; }
41 static inline timer
*timers_first(struct timeloop
*loop
)
42 { return (loop
->timers
.used
> 1) ? loop
->timers
.data
[1] : NULL
; }
44 extern struct timeloop main_timeloop
;
46 btime
current_time(void);
47 btime
current_real_time(void);
49 //#define now (current_time() TO_S)
50 //#define now_real (current_real_time() TO_S)
51 extern btime boot_time
;
53 timer
*tm_new(pool
*p
);
54 void tm_set(timer
*t
, btime when
);
55 void tm_start(timer
*t
, btime after
);
56 void tm_stop(timer
*t
);
61 return t
->expires
!= 0;
67 btime now_
= current_time();
68 return (t
->expires
> now_
) ? (t
->expires
- now_
) : 0;
72 tm_new_init(pool
*p
, void (*hook
)(struct timer
*), void *data
, uint rec
, uint rand
)
83 tm_set_max(timer
*t
, btime when
)
85 if (when
> t
->expires
)
90 tm_start_max(timer
*t
, btime after
)
92 btime rem
= tm_remains(t
);
93 tm_start(t
, MAX_(rem
, after
));
97 void times_init(struct timeloop
*loop
);
98 void times_update(struct timeloop
*loop
);
99 void times_update_real_time(struct timeloop
*loop
);
102 void timers_init(struct timeloop
*loop
, pool
*p
);
103 void timers_fire(struct timeloop
*loop
);
105 void timer_init(void);
109 const char *fmt1
, *fmt2
;
113 #define TM_ISO_SHORT_S (struct timeformat){"%T", "%F", (s64) (20*3600) S_}
114 #define TM_ISO_SHORT_MS (struct timeformat){"%T.%3f", "%F", (s64) (20*3600) S_}
115 #define TM_ISO_SHORT_US (struct timeformat){"%T.%6f", "%F", (s64) (20*3600) S_}
117 #define TM_ISO_LONG_S (struct timeformat){"%F %T", NULL, 0}
118 #define TM_ISO_LONG_MS (struct timeformat){"%F %T.%3f", NULL, 0}
119 #define TM_ISO_LONG_US (struct timeformat){"%F %T.%6f", NULL, 0}
121 #define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_time() */
123 btime
tm_parse_time(const char *x
);
124 void tm_format_time(char *x
, struct timeformat
*fmt
, btime t
);
125 int tm_format_real_time(char *x
, size_t max
, const char *fmt
, btime t
);