]>
jfr.im git - irc/evilnet/x3.git/blob - src/timeq.c
1 /* timeq.c - time-based event queue
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
35 timeq_del(0, 0, 0, TIMEQ_IGNORE_WHEN
|TIMEQ_IGNORE_FUNC
|TIMEQ_IGNORE_DATA
);
42 timeq
= heap_new(int_comparator
);
43 reg_exit_func(timeq_cleanup
);
50 heap_peek(timeq
, &time
, 0);
55 timeq_add(time_t when
, timeq_func func
, void *data
)
57 struct timeq_entry
*ent
;
59 ent
= malloc(sizeof(struct timeq_entry
));
63 heap_insert(timeq
, w
, ent
);
74 timeq_del_matching(void *key
, void *data
, void *extra
)
76 struct timeq_entry
*a
= data
;
77 struct timeq_extra
*b
= extra
;
78 if (((b
->mask
& TIMEQ_IGNORE_WHEN
) || ((time_t)key
== b
->when
))
79 && ((b
->mask
& TIMEQ_IGNORE_FUNC
) || (a
->func
== b
->func
))
80 && ((b
->mask
& TIMEQ_IGNORE_DATA
) || (a
->data
== b
->data
))) {
89 timeq_del(time_t when
, timeq_func func
, void *data
, int mask
)
91 struct timeq_extra extra
;
96 heap_remove_pred(timeq
, timeq_del_matching
, &extra
);
102 return heap_size(timeq
);
109 struct timeq_entry
*ent
;
110 while (heap_size(timeq
) > 0) {
111 heap_peek(timeq
, &k
, &d
);
116 ent
->func(ent
->data
);