Skip to content
Snippets Groups Projects
Commit 038fd94b authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Fixed heap node comparison function.

parent be07634f
No related branches found
No related tags found
No related merge requests found
......@@ -26,10 +26,10 @@
#define OPENBSD_SLAB_BROKEN
#endif
static int compare_event_heap_nodes(event_t *e1, event_t *e2)
/* According to libucw heap, x<y should return non-zero else zero value. */
static int compare_event_heap_nodes(event_t **e1, event_t **e2)
{
if (timercmp(&e1->tv, &e2->tv, <)) return -1;
if (timercmp(&e1->tv, &e2->tv, >)) return 1;
if (timercmp(&(*e1)->tv, &(*e2)->tv, <)) return 1;
return 0;
}
......@@ -144,6 +144,11 @@ void evsched_event_free(evsched_t *s, event_t *ev)
if (!s || !ev) {
return;
}
int found = 0;
if ((found = heap_find(&s->heap, &ev))) {
heap_delete(&s->heap, found);
}
#ifndef OPENBSD_SLAB_BROKEN
pthread_mutex_lock(&s->cache.lock);
......
......@@ -46,8 +46,8 @@
void _def_swap(struct heap *h, void *e1, void *e2)
{
if (e1 == e2) return;
void *tmp = HTEMPELEMENT(h);
memcpy(tmp, e1, h->elm_size);
memcpy(e1, e2, h->elm_size);
memcpy(e2, tmp, h->elm_size);
......@@ -75,8 +75,8 @@ static inline void _heap_bubble_down(struct heap *h, int e)
{
e1 = 2*e;
if(e1 > h->num) break;
if((h->cmp(HELEMENT(h, e),HELEMENT(h,e1)) < 0) && (e1 == h->num) || (h->cmp(HELEMENT(h, e),HELEMENT(h,e1+1)) < 0)) break;
if(e1 != h->num && (h->cmp(HELEMENT(h, e1+1),HELEMENT(h,e1)) < 0)) e1++;
if(((h->cmp(HELEMENT(h, e),HELEMENT(h,e1)) < 0) && (e1 == h->num)) || (h->cmp(HELEMENT(h, e),HELEMENT(h,e1+1)) < 0)) break;
if((e1 != h->num) && (h->cmp(HELEMENT(h, e1+1), HELEMENT(h,e1)) < 0)) e1++;
h->swap(h,HELEMENT(h,e),HELEMENT(h,e1));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment