RCSID("$Id$")
#include <freeradius-devel/libradius.h>
+#include <freeradius-devel/heap.h>
#include <freeradius-devel/event.h>
typedef struct fr_event_fd_t {
struct fr_event_list_t {
- rbtree_t *times;
+ fr_heap_t *times;
int changed;
int maxfd;
void *ctx;
struct timeval when;
fr_event_t **ev_p;
- rbnode_t *node;
+ int heap;
};
{
if (!el) return;
- rbtree_free(el->times);
+ fr_heap_delete(el->times);
free(el);
}
if (!el) return NULL;
memset(el, 0, sizeof(*el));
- el->times = rbtree_create(fr_event_list_time_cmp,
- free, 0);
+ el->times = fr_heap_create(fr_event_list_time_cmp,
+ offsetof(fr_event_t, heap));
if (!el->times) {
fr_event_list_free(el);
return NULL;
{
if (!el) return 0;
- return rbtree_num_elements(el->times);
+ return fr_heap_num_elements(el->times);
}
if (ev->ev_p) *(ev->ev_p) = NULL;
*ev_p = NULL;
- rbtree_delete(el->times, ev->node);
+ fr_heap_extract(el->times, ev);
return 1;
}
ev->when = *when;
ev->ev_p = ev_p;
- /*
- * There's a tiny chance that two events will be
- * scheduled at the same time. If this happens, we
- * increase the usec counter by 1, in order to avoid the
- * duplicate. If we can't insert it after 10 tries, die.
- */
- ev->node = rbtree_insertnode(el->times, ev);
- if (!ev->node) {
- if (rbtree_finddata(el->times, ev)) {
- int i;
-
- for (i = 0; i < 10; i++) {
- ev->when.tv_usec++;
- if (ev->when.tv_usec >= 1000000) {
- ev->when.tv_usec = 0;
- ev->when.tv_sec++;
- }
-
- if (rbtree_finddata(el->times, ev)) {
- continue;
- }
-
- ev->node = rbtree_insertnode(el->times, ev);
- if (!ev->node) { /* error */
- break;
- }
-
- if (ev_p) *ev_p = ev;
- return 1;
- }
-
- }
+ if (!fr_heap_insert(el->times, ev)) {
free(ev);
return 0;
}
if (!el) return 0;
- if (rbtree_num_elements(el->times) == 0) {
+ if (fr_heap_num_elements(el->times) == 0) {
when->tv_sec = 0;
when->tv_usec = 0;
return 0;
}
- ev = rbtree_min(el->times);
+ ev = fr_heap_peek(el->times);
if (!ev) {
when->tv_sec = 0;
when->tv_usec = 0;
when.tv_sec = 0;
when.tv_usec = 0;
- if (rbtree_num_elements(el->times) > 0) {
+ if (fr_heap_num_elements(el->times) > 0) {
fr_event_t *ev;
- ev = rbtree_min(el->times);
+ ev = fr_heap_peek(el->times);
if (!ev) _exit(42);
gettimeofday(&el->now, NULL);
return 0;
}
- if (rbtree_num_elements(el->times) > 0) {
+ if (fr_heap_num_elements(el->times) > 0) {
do {
gettimeofday(&el->now, NULL);
when = el->now;