1 /* timeq.c - time-based event queue
2 * Copyright 2000-2004 srvx Development Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email srvx-maintainers@srvx.net.
33 timeq_del(0, 0, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_FUNC|TIMEQ_IGNORE_DATA);
40 timeq = heap_new(int_comparator);
41 reg_exit_func(timeq_cleanup);
48 heap_peek(timeq, &time, 0);
53 timeq_add(time_t when, timeq_func func, void *data)
55 struct timeq_entry *ent;
57 ent = malloc(sizeof(struct timeq_entry));
61 heap_insert(timeq, w, ent);
72 timeq_del_matching(void *key, void *data, void *extra)
74 struct timeq_entry *a = data;
75 struct timeq_extra *b = extra;
76 if (((b->mask & TIMEQ_IGNORE_WHEN) || ((time_t)key == b->when))
77 && ((b->mask & TIMEQ_IGNORE_FUNC) || (a->func == b->func))
78 && ((b->mask & TIMEQ_IGNORE_DATA) || (a->data == b->data))) {
87 timeq_del(time_t when, timeq_func func, void *data, int mask)
89 struct timeq_extra extra;
94 heap_remove_pred(timeq, timeq_del_matching, &extra);
100 return heap_size(timeq);
107 struct timeq_entry *ent;
108 while (heap_size(timeq) > 0) {
109 heap_peek(timeq, &k, &d);
114 ent->func(ent->data);