@@ -39,29 +39,37 @@ namespace events {
3939
4040/* * EventQueue
4141 *
42- * Flexible event queue
42+ * Flexible event queue for dispatching events
4343 */
4444class EventQueue {
4545public:
46- /* * Create an event queue
46+ /* * EventQueue lifetime
4747 *
48- * @param queue_size Size of buffer to use for events
49- * (default: EVENTS_QUEUE_SIZE)
50- * @param queue_pointer Pointer to memory region to use for events
51- * (default: NULL)
52- */
53- EventQueue (unsigned queue_size=EVENTS_QUEUE_SIZE,
54- unsigned char *queue_pointer=NULL );
55-
56- /* * Destroy an event queue
48+ * Create and destroy event queues. The event queue either allocates
49+ * a buffer of the specified size with malloc or uses the user provided
50+ * buffer.
51+ *
52+ * @param size Size of buffer to use for events in bytes
53+ * (default to EVENTS_QUEUE_SIZE)
54+ * @param buffer Pointer to buffer to use for events
55+ * (default to NULL)
5756 */
57+ EventQueue (unsigned size=EVENTS_QUEUE_SIZE, unsigned char *buffer=NULL );
5858 ~EventQueue ();
5959
60- /* * Dispatch pending events
61- * @param ms Time to wait for events in milliseconds, 0 will return
62- * immediately if no events are pending, a negative
63- * value will dispatch events forever
64- * (default: -1)
60+ /* * Dispatch events
61+ *
62+ * Executes events until the specified milliseconds have passed.
63+ * If ms is negative, the dispatch function will dispatch events
64+ * indefinitely or until break_dispatch is called on this queue.
65+ *
66+ * When called with a finite timeout, the dispatch function is garunteed
67+ * to terminate. When called with a timeout of 0, the dispatch function
68+ * does not wait and is irq safe.
69+ *
70+ * @param ms Time to wait for events in milliseconds, a negative
71+ * value will dispatch events indefinitely
72+ * (default to -1)
6573 */
6674 void dispatch (int ms);
6775 void dispatch () { dispatch (-1 ); }
@@ -73,27 +81,43 @@ class EventQueue {
7381 */
7482 void break_dispatch ();
7583
76- /* Monotonic counter for the event queue
77- * @return A monotonically incrementing counter in milliseconds
78- * this count intentionally overflows to 0 after 2^32-1
84+ /* * Millisecond counter
85+ *
86+ * Returns the underlying tick of the event queue represented as the
87+ * number of milliseconds that have passed since an arbitrary point in
88+ * time. Intentionally overflows to 0 after 2^32-1.
89+ *
90+ * @return The underlying tick of the event queue in milliseconds
7991 */
8092 unsigned tick ();
8193
82- /* * Cancel events that are in flight
94+ /* * Cancel an in-flight event
95+ *
96+ * Attempts to cancel an event referenced by the unique id returned from
97+ * one of the call functions. It is safe to call cancel after an event
98+ * has already been dispatched.
99+ *
100+ * The cancel function is irq safe.
83101 *
84- * If event has already been dispatched or does not exist, no error occurs.
102+ * If called while the event queue's dispatch loop is active, the cancel
103+ * function does not garuntee that the event will not execute after it
104+ * returns, as the event may have already begun executing.
85105 *
86- * @param id Event id to cancel
87- * @note This can not stop a currently executing event
106+ * @param id Unique id of the event
88107 */
89108 void cancel (int id);
90109
91110 /* * Background an event queue onto a single-shot timer
92111 *
93112 * The provided update function will be called to indicate when the queue
94113 * should be dispatched. A negative timeout will be passed to the update
95- * function when the timer is no longer needed. A null update function
96- * will disable the existing timer.
114+ * function when the time is no longer needed.
115+ *
116+ * Passing a null update function disables the existing timre.
117+ *
118+ * The background function allows an event queue to take advantage of
119+ * hardware timers or even other event loops, allowing an event queue to
120+ * be effectively backgrounded.
97121 *
98122 * @param update Function called to indicate when the queue should be
99123 * dispatched
@@ -103,20 +127,33 @@ class EventQueue {
103127 /* * Chain an event queue onto another event queue
104128 *
105129 * After chaining a queue to a target, calling dispatch on the target
106- * queue will also dispatch events from this queue. The queues will use
107- * their own buffers and events are handled independently. A null queue
108- * as the target will unchain the queue.
130+ * queue will also dispatch events from this queue. The queues use
131+ * their own buffers and events must be handled independently.
132+ *
133+ * A null queue as the target will unchain the existing queue.
109134 *
110- * @param target Queue to chain onto
135+ * The chain function allows multiple event queuest to be composed,
136+ * sharing the context of a dispatch loop while still being managed
137+ * independently
138+ *
139+ * @param target Queue that will dispatch this queue's events as a
140+ * part of its dispatch loop
111141 */
112142 void chain (EventQueue *target);
113143
114144 /* * Post an event to the queue
115145 *
116- * @param f Function to call on event dispatch
146+ * The specified callback will be executed in the context of the event
147+ * queue's dispatch loop.
148+ *
149+ * The call function is irq safe and can act as a mechanism for moving
150+ * events out of irq contexts.
151+ *
152+ * @param f Function to execute in the context of the dispatch loop
117153 * @param a0..a4 Arguments to pass to the callback
118- * @return A positive id representing the event in the queue,
119- * or 0 on failure
154+ * @return A unique id that represents the posted event and can
155+ * be passed to cancel, or an id of 0 if there is not
156+ * enough memory to allocate the event.
120157 */
121158 template <typename F>
122159 int call (F f) {
@@ -157,11 +194,18 @@ class EventQueue {
157194
158195 /* * Post an event to the queue after a specified delay
159196 *
160- * @param f Function to call on event dispatch
197+ * The specified callback will be executed in the context of the event
198+ * queue's dispatch loop.
199+ *
200+ * The call_in function is irq safe and can act as a mechanism for moving
201+ * events out of irq contexts.
202+ *
203+ * @param f Function to execute in the context of the dispatch loop
161204 * @param a0..a4 Arguments to pass to the callback
162205 * @param ms Time to delay in milliseconds
163- * @return A positive id representing the event in the queue,
164- * or 0 on failure
206+ * @return A unique id that represents the posted event and can
207+ * be passed to cancel, or an id of 0 if there is not
208+ * enough memory to allocate the event.
165209 */
166210 template <typename F>
167211 int call_in (int ms, F f) {
@@ -203,11 +247,18 @@ class EventQueue {
203247
204248 /* * Post an event to the queue periodically
205249 *
206- * @param f Function to call on event dispatch
250+ * The specified callback will be executed in the context of the event
251+ * queue's dispatch loop.
252+ *
253+ * The call_every function is irq safe and can act as a mechanism for
254+ * moving events out of irq contexts.
255+ *
256+ * @param f Function to execute in the context of the dispatch loop
207257 * @param a0..a4 Arguments to pass to the callback
208258 * @param ms Period of the event in milliseconds
209- * @return A positive id representing the event in the queue,
210- * or 0 on failure
259+ * @return A unique id that represents the posted event and can
260+ * be passed to cancel, or an id of 0 if there is not
261+ * enough memory to allocate the event.
211262 */
212263 template <typename F>
213264 int call_every (int ms, F f) {
0 commit comments