6 * timer - efficient implementation of rarely-expiring timers.
8 * This is a lazy implementation of timers: you can add and delete timers
9 * very quickly, and they are only sorted as their expiry approaches.
11 * This is a common case for timeouts, which must often be set, but
15 * // Silly example which outputs strings until timers expire.
16 * #include <ccan/timer/timer.h>
17 * #include <ccan/time/time.h>
21 * struct timed_string {
22 * struct list_node node;
27 * int main(int argc, char *argv[])
29 * struct timers timers;
30 * struct list_head strings;
32 * struct timed_string *s;
35 * timers_init(&timers, time_mono());
36 * list_head_init(&strings);
39 * s = malloc(sizeof(*s));
40 * s->string = argv[1];
41 * timer_addrel(&timers, &s->timer,
42 * time_from_msec(atol(argv[2])));
43 * list_add_tail(&strings, &s->node);
47 * while (!list_empty(&strings)) {
48 * struct timemono now = time_mono();
49 * list_for_each(&strings, s, node)
50 * printf("%s", s->string);
51 * while ((t = timers_expire(&timers, now)) != NULL) {
52 * s = container_of(t, struct timed_string, timer);
53 * list_del_from(&strings, &s->node);
61 * License: LGPL (v2.1 or any later version)
62 * Author: Rusty Russell <rusty@rustcorp.com.au>
64 int main(int argc, char *argv[])
66 /* Expect exactly one argument */
70 if (strcmp(argv[1], "depends") == 0) {
71 printf("ccan/array_size\n");
72 printf("ccan/ilog\n");
73 printf("ccan/likely\n");
74 printf("ccan/list\n");
75 printf("ccan/time\n");