Commit | Line | Data |
---|---|---|
1ca80abd PP |
1 | #ifndef BABELTRACE_GRAPH_NOTIFICATION_HEAP_H |
2 | #define BABELTRACE_GRAPH_NOTIFICATION_HEAP_H | |
7c6ea146 JG |
3 | |
4 | /* | |
6a5c560c | 5 | * Babeltrace - Notification Heap |
7c6ea146 JG |
6 | * |
7 | * Copyright (c) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
9 | * | |
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
11 | * of this software and associated documentation files (the "Software"), to deal | |
12 | * in the Software without restriction, including without limitation the rights | |
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
14 | * copies of the Software, and to permit persons to whom the Software is | |
15 | * furnished to do so, subject to the following conditions: | |
16 | * | |
17 | * The above copyright notice and this permission notice shall be included in | |
18 | * all copies or substantial portions of the Software. | |
19 | * | |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
26 | * SOFTWARE. | |
27 | */ | |
28 | ||
29 | #include <stddef.h> | |
b2e0c907 | 30 | #include <babeltrace/graph/notification.h> |
c55a9f58 | 31 | #include <babeltrace/types.h> |
7c6ea146 JG |
32 | |
33 | /** | |
34 | * bt_notification_time_compare - Compare two notifications' timestamps | |
35 | * | |
36 | * Compare two notifications in the time domain. Return true if 'a' happened | |
37 | * prior to 'b'. In the case where both notifications are deemed to have | |
38 | * happened at the same time, an implementation-defined critarion shall be | |
39 | * used to order the notifications. This criterion shall ensure a consistent | |
40 | * ordering over multiple runs. | |
41 | */ | |
c55a9f58 | 42 | typedef bt_bool (*bt_notification_time_compare_func)( |
352fe16f JG |
43 | struct bt_notification *a, struct bt_notification *b, |
44 | void *user_data); | |
7c6ea146 JG |
45 | |
46 | /** | |
47 | * bt_notification_heap_create - create a new bt_notification heap. | |
48 | * | |
49 | * @comparator: Function to use for notification comparisons. | |
50 | * | |
51 | * Returns a new notification heap, NULL on error. | |
52 | */ | |
53 | extern struct bt_notification_heap *bt_notification_heap_create( | |
352fe16f | 54 | bt_notification_time_compare_func comparator, void *user_data); |
7c6ea146 JG |
55 | |
56 | /** | |
57 | * bt_notification_heap_insert - insert an element into the heap | |
58 | * | |
59 | * @heap: the heap to be operated on | |
60 | * @notification: the notification to add | |
61 | * | |
62 | * Insert a notification into the heap. | |
63 | * | |
64 | * Returns 0 on success, a negative value on error. | |
65 | */ | |
66 | extern int bt_notification_heap_insert(struct bt_notification_heap *heap, | |
67 | struct bt_notification *notification); | |
68 | ||
69 | /** | |
70 | * bt_notification_heap_peek - return the element on top of the heap. | |
71 | * | |
72 | * @heap: the heap to be operated on | |
73 | * | |
74 | * Returns the top element of the heap, without performing any modification | |
75 | * to the heap structure. Returns NULL if the heap is empty. The returned | |
76 | * notification must be bt_put() by the caller. | |
77 | */ | |
78 | extern struct bt_notification *bt_notification_heap_peek( | |
79 | struct bt_notification_heap *heap); | |
80 | ||
81 | /** | |
82 | * bt_notification_heap_pop - remove the element sitting on top of the heap. | |
83 | * @heap: the heap to be operated on | |
84 | * | |
85 | * Returns the top element of the heap. The element is removed from the | |
86 | * heap. Returns NULL if the heap is empty. The returned notification must be | |
87 | * bt_put() by the caller. | |
88 | */ | |
6a5c560c JG |
89 | extern struct bt_notification *bt_notification_heap_pop( |
90 | struct bt_notification_heap *heap); | |
7c6ea146 | 91 | |
1ca80abd | 92 | #endif /* BABELTRACE_GRAPH_NOTIFICATION_HEAP_H */ |