* ordering over multiple runs.
*/
typedef bool (*bt_notification_time_compare_func)(
- struct bt_notification *a, struct bt_notification *b);
+ struct bt_notification *a, struct bt_notification *b,
+ void *user_data);
/**
* bt_notification_heap_create - create a new bt_notification heap.
* Returns a new notification heap, NULL on error.
*/
extern struct bt_notification_heap *bt_notification_heap_create(
- bt_notification_time_compare_func comparator);
+ bt_notification_time_compare_func comparator, void *user_data);
/**
* bt_notification_heap_insert - insert an element into the heap
for (i = 1; i < heap->count; i++) {
assert(!heap->compare(g_ptr_array_index(heap->ptrs, i),
- g_ptr_array_index(heap->ptrs, 0)));
+ g_ptr_array_index(heap->ptrs, 0),
+ heap->compare_data));
}
}
#else
l = left(i);
r = right(i);
- if (l < heap->count && heap->compare(ptrs[l], ptrs[i])) {
+ if (l < heap->count && heap->compare(ptrs[l], ptrs[i],
+ heap->compare_data)) {
largest = l;
} else {
largest = i;
}
- if (r < heap->count && heap->compare(ptrs[r], ptrs[largest])) {
+ if (r < heap->count && heap->compare(ptrs[r], ptrs[largest],
+ heap->compare_data)) {
largest = r;
}
if (unlikely(largest == i)) {
}
struct bt_notification_heap *bt_notification_heap_create(
- bt_notification_time_compare_func comparator)
+ bt_notification_time_compare_func comparator, void *user_data)
{
struct bt_notification_heap *heap = NULL;
}
heap->compare = comparator;
+ heap->compare_data = user_data;
end:
return heap;
}
ptrs = (struct bt_notification **) heap->ptrs->pdata;
pos = heap->count - 1;
- while (pos > 0 && heap->compare(notification, ptrs[parent(pos)])) {
+ while (pos > 0 && heap->compare(notification, ptrs[parent(pos)],
+ heap->compare_data)) {
/* Move parent down until we find the right spot. */
ptrs[pos] = ptrs[parent(pos)];
pos = parent(pos);
}
static
-bool compare_notifications(struct bt_notification *a, struct bt_notification *b)
+bool compare_notifications(struct bt_notification *a, struct bt_notification *b,
+ void *unused)
{
uint64_t val_a = ((struct dummy_notification *) a)->value;
uint64_t val_b = ((struct dummy_notification *) b)->value;
/* Initialize tap harness before any tests */
plan_tests(NR_TESTS);
- heap = bt_notification_heap_create(compare_notifications);
+ heap = bt_notification_heap_create(compare_notifications, NULL);
ok(heap, "Created a notification heap");
/* Insert 10 000 notifications with random values. */