-
Notifications
You must be signed in to change notification settings - Fork 9
/
tiny_event_queue.h
47 lines (40 loc) · 1.39 KB
/
tiny_event_queue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*!
* @file
* @brief Event queue that stores queued events in a ring buffer.
*
* This implementation is interrupt-safe provided that events are
* queued in an interrupt context and dequeued in a non-interrupt
* context. Queueing of one event must be completed before the next
* event can be queued so interrupt safety is broken if a high
* priority interrupt queues while interrupting a low priority
* interrupt that is also queueing.
*/
#ifndef tiny_event_queue_h
#define tiny_event_queue_h
#include <stdbool.h>
#include <stddef.h>
#include "i_tiny_event_queue.h"
#include "tiny_ring_buffer.h"
typedef void (*tiny_queue_unable_to_enqueue_callback_t)(void);
typedef struct {
i_tiny_event_queue_t interface;
tiny_ring_buffer_t ring_buffer;
tiny_queue_unable_to_enqueue_callback_t unable_to_queue_callback;
} tiny_event_queue_t;
/*!
* Initializes the event queue with the provided buffer. Larger
* buffers allow for more events to be queued simultaneously. When
* an event is unable to be queued, the provided callback is used
* to notify the client.
*/
void tiny_event_queue_init(
tiny_event_queue_t* self,
void* buffer,
unsigned buffer_size,
tiny_queue_unable_to_enqueue_callback_t unable_to_queue_callback);
/*!
* Dequeues and raises at most one queued event. Returns true if an
* event was raised and false otherwise.
*/
bool tiny_event_queue_run(tiny_event_queue_t* self);
#endif