Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Commit fe021da

Browse files
committed
Updated more documentation
- revisions to the README - misspellings in equeue.h
1 parent 68033ab commit fe021da

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
## The equeue library ##
22

33
The equeue library is designed as a simple but powerful library for scheduling
4-
events on composable event queues.
4+
events on composable queues.
55

66
``` c
77
#include "equeue.h"
88
#include <stdio.h>
99

10-
void print(void *s) {
11-
puts((const char *)s);
12-
}
13-
1410
int main() {
1511
// creates a queue with space for 32 basic events
1612
equeue_t queue;
@@ -31,26 +27,26 @@ int main() {
3127
```
3228

3329
The equeue library can be used as a normal event loop, or it can be
34-
backgrounded on a single hardware timer or even another event loop.
35-
The equeue library is both thread and irq safe, and provides functions
36-
for easily composing multiple queues.
30+
backgrounded on a single hardware timer or even another event loop. It
31+
is both thread and irq safe, and provides functions for easily composing
32+
multiple queues.
3733

3834
The equeue library can act as a drop-in scheduler, provide synchronization
3935
between multiple threads, or just act as a mechanism for moving events
4036
out of interrupt contexts.
4137

4238
## Documentation ##
4339

44-
Unless it is elaborated, the in-depth documentation of the specific functions
45-
can be found in [equeue.h](equeue.h).
40+
The in-depth documentation on specific functions can be found in
41+
[equeue.h](equeue.h).
4642

4743
The core of the equeue library is the `equeue_t` type which represents a
48-
single event queue, and the `equeue_dispath` function which runs the equeue,
44+
single event queue, and the `equeue_dispatch` function which runs the equeue,
4945
providing the context for executing events.
5046

5147
On top of this, `equeue_call`, `equeue_call_in`, and `equeue_call_every`
52-
provide an easy method of posting events to be executed in the context
53-
of the `equeue_dispatch` function.
48+
provide easy methods for posting events to execute in the context of the
49+
`equeue_dispatch` function.
5450

5551
``` c
5652
#include "equeue.h"
@@ -77,30 +73,30 @@ int main() {
7773
}
7874
```
7975
80-
In addition to simple events, an event can be manually allocated with
76+
In addition to simple callbacks, an event can be manually allocated with
8177
`equeue_alloc` and posted with `equeue_post` to allow passing an arbitrary
82-
amount of data to the execution of the event. This memory is allocated out
78+
amount of context to the execution of the event. This memory is allocated out
8379
of the equeue's buffer, and dynamic memory can be completely avoided.
8480
8581
The equeue allocator is designed to minimize jitter in interrupt contexts as
8682
well as avoid memory fragmentation on small devices. The allocator achieves
8783
both constant-runtime and zero-fragmentation for fixed-size events, however
88-
grows linearly as the quantity of different sized allocations increases.
84+
grows linearly as the quantity of differently-sized allocations increases.
8985
9086
``` c
9187
#include "equeue.h"
9288
9389
equeue_t queue;
9490
9591
// arbitrary data can be moved to a different context
96-
int enet_callback(void *buffer, int size) {
92+
int enet_consume(void *buffer, int size) {
9793
if (size > 512) {
9894
size = 512;
9995
}
10096
101-
void *event = equeue_alloc(&queue, 512);
102-
memcpy(event, buffer, size);
103-
equeue_post(&queue, event);
97+
void *data = equeue_alloc(&queue, 512);
98+
memcpy(data, buffer, size);
99+
equeue_post(&queue, handle_data_elsewhere, data);
104100
105101
return size;
106102
}
@@ -133,12 +129,11 @@ void sonar_read(void) {
133129
134130
From an architectural standpoint, event queues easily align with module
135131
boundaries, where internal state can be implicitly synchronized through
136-
event registration. Multiple modules can easily use event queues running
137-
in separate threads.
132+
event dispatch.
138133
139-
Alternatively, multiple event queues can be easily composed through the
140-
`equeue_chain` function, which allows multiple event queues to share the
141-
context of a single `equeue_dispatch` call.
134+
On platforms where multiple threads are unavailable, multiple modules
135+
can use independent event queues and still be composed through the
136+
`equeue_chain` function.
142137
143138
``` c
144139
#include "equeue.h"
@@ -166,8 +161,7 @@ void sonar_create(struct sonar *s, equeue_t *target) {
166161
equeue_call_in(&s->queue, 5, sonar_update, s);
167162
}
168163
169-
// although the above is perfectly synchronized, we can run these
170-
// modules on a single event queue
164+
// all of the above queues can be combined into a single thread of execution
171165
int main() {
172166
equeue_t queue;
173167
equeue_create(&queue, 1024);
@@ -180,7 +174,7 @@ int main() {
180174
struct slam slam;
181175
slam_create(&slam, &queue);
182176
183-
// dispatches events for all of the modules
177+
// dispatches events from all of the modules
184178
equeue_dispatch(&queue, -1);
185179
}
186180
```

equeue.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C" {
2121

2222

2323
// The minimum size of an event
24-
// This size is garunteed to fit events created by event_call
24+
// This size is guaranteed to fit events created by event_call
2525
#define EQUEUE_EVENT_SIZE (sizeof(struct equeue_event) + 2*sizeof(void*))
2626

2727
// Internal event structure
@@ -89,9 +89,9 @@ void equeue_destroy(equeue_t *queue);
8989
// negative, equeue_dispatch will dispatch events indefinitely or until
9090
// equeue_break is called on this queue.
9191
//
92-
// When called with a finite timeout, the equeue_dispatch function is garunteed
93-
// to terminate. When called with a timeout of 0, the equeue_dispatch does not
94-
// wait and is irq safe.
92+
// When called with a finite timeout, the equeue_dispatch function is
93+
// guaranteed to terminate. When called with a timeout of 0, the
94+
// equeue_dispatch does not wait and is irq safe.
9595
void equeue_dispatch(equeue_t *queue, int ms);
9696

9797
// Break out of a running event loop
@@ -171,7 +171,7 @@ int equeue_post(equeue_t *queue, void (*cb)(void *), void *event);
171171
// The equeue_cancel function is irq safe.
172172
//
173173
// If called while the event queue's dispatch loop is active, equeue_cancel
174-
// does not garuntee that the event will not not execute after it returns as
174+
// does not guarantee that the event will not not execute after it returns as
175175
// the event may have already begun executing.
176176
void equeue_cancel(equeue_t *queue, int id);
177177

@@ -198,7 +198,7 @@ void equeue_background(equeue_t *queue,
198198
// Passing a null queue as the target will unchain the existing queue.
199199
//
200200
// The equeue_chain function allows multiple equeues to be composed, sharing
201-
// the context of a dispatch loop while still being managed independtly.
201+
// the context of a dispatch loop while still being managed independently.
202202
void equeue_chain(equeue_t *queue, equeue_t *target);
203203

204204

0 commit comments

Comments
 (0)