]>
Commit | Line | Data |
---|---|---|
2dcbb2a0 SW |
1 | #include "sends.h" |
2 | ||
17461dec | 3 | static uint32_t next_send(press_t *s) { |
2dcbb2a0 SW |
4 | return s->timestamp + (1 << s->send_count) - 1; |
5 | } | |
6 | ||
7 | bool next_send_less_than(void *user_data, pheap_node_id_t a, | |
8 | pheap_node_id_t b) { | |
17461dec SW |
9 | press_t *presses = (press_t *)user_data; |
10 | return next_send(&presses[a]) < next_send(&presses[b]); | |
2dcbb2a0 | 11 | } |
67001c93 | 12 | |
17461dec SW |
13 | void create_press(press_t *presses, pheap_t *sleeps_heap, uint32_t timestamp, |
14 | u16_t seq) { | |
67001c93 SW |
15 | pheap_node_id_t i = ph_new_node(sleeps_heap); |
16 | if (i == 0) { | |
17 | /* TODO: Don't drop new presses just because sleeps_heap is full of old | |
18 | * presses. */ | |
19 | return; | |
20 | } | |
17461dec SW |
21 | presses[i].timestamp = timestamp; |
22 | presses[i].seq = seq; | |
23 | presses[i].send_count = 0; | |
67001c93 SW |
24 | ph_insert_node(sleeps_heap, i); |
25 | } | |
b512ec26 | 26 | |
17461dec | 27 | int32_t next_scheduled_send(press_t *presses, pheap_t *sleeps_heap) { |
b512ec26 SW |
28 | pheap_node_id_t i = ph_peek_head(sleeps_heap); |
29 | if (i == 0) | |
30 | return -1; | |
17461dec | 31 | return next_send(&presses[i]); |
b512ec26 | 32 | } |