Note! This project has moved to github.com/armmbed/mbed-events
This repository has been superceded
This project has moved to mbed-events
Composable event loops combine the cheap synchronicity of event loops with the composability of preempted threads.
Two modular event queue classes are provided:
- EventLoop - for loops coupled with a c++ managed thread
- EventQueue - for manually managed event queues
The Event class takes advantage of the extensibility of FuncPtr to allow an event to be passed through APIs as a normal function.
More information on composable event loops.
EventQueue.h@0:b1b901ae3696, 2016-04-20 (annotated)
- Committer:
- Christopher Haster
- Date:
- Wed Apr 20 11:43:51 2016 -0500
- Revision:
- 0:b1b901ae3696
- Child:
- 1:2202c19570e5
Initial commit of Event and EventQueue classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
0:b1b901ae3696 | 1 | /* EventQueue |
Christopher Haster |
0:b1b901ae3696 | 2 | * |
Christopher Haster |
0:b1b901ae3696 | 3 | * Flexible queue for managing events |
Christopher Haster |
0:b1b901ae3696 | 4 | */ |
Christopher Haster |
0:b1b901ae3696 | 5 | #ifndef EVENT_QUEUE_H |
Christopher Haster |
0:b1b901ae3696 | 6 | #define EVENT_QUEUE_H |
Christopher Haster |
0:b1b901ae3696 | 7 | |
Christopher Haster |
0:b1b901ae3696 | 8 | |
Christopher Haster |
0:b1b901ae3696 | 9 | /** Flexible queue for managing events |
Christopher Haster |
0:b1b901ae3696 | 10 | */ |
Christopher Haster |
0:b1b901ae3696 | 11 | class EventQueue { |
Christopher Haster |
0:b1b901ae3696 | 12 | public: |
Christopher Haster |
0:b1b901ae3696 | 13 | /** Dispatch pending events |
Christopher Haster |
0:b1b901ae3696 | 14 | * @param milli Time to wait for events in milliseconds, |
Christopher Haster |
0:b1b901ae3696 | 15 | * 0 indicates to return immediately if no events are pending |
Christopher Haster |
0:b1b901ae3696 | 16 | */ |
Christopher Haster |
0:b1b901ae3696 | 17 | void dispatch(unsigned milli=-1); |
Christopher Haster |
0:b1b901ae3696 | 18 | |
Christopher Haster |
0:b1b901ae3696 | 19 | private: |
Christopher Haster |
0:b1b901ae3696 | 20 | struct event { |
Christopher Haster |
0:b1b901ae3696 | 21 | struct event *next; |
Christopher Haster |
0:b1b901ae3696 | 22 | void (*callback)(void *); |
Christopher Haster |
0:b1b901ae3696 | 23 | void *data; |
Christopher Haster |
0:b1b901ae3696 | 24 | }; |
Christopher Haster |
0:b1b901ae3696 | 25 | |
Christopher Haster |
0:b1b901ae3696 | 26 | void event_register(struct event *event); |
Christopher Haster |
0:b1b901ae3696 | 27 | void event_unregister(struct event *event); |
Christopher Haster |
0:b1b901ae3696 | 28 | |
Christopher Haster |
0:b1b901ae3696 | 29 | template <typename F> |
Christopher Haster |
0:b1b901ae3696 | 30 | friend class Event; |
Christopher Haster |
0:b1b901ae3696 | 31 | |
Christopher Haster |
0:b1b901ae3696 | 32 | struct event *_queue; |
Christopher Haster |
0:b1b901ae3696 | 33 | }; |
Christopher Haster |
0:b1b901ae3696 | 34 | |
Christopher Haster |
0:b1b901ae3696 | 35 | |
Christopher Haster |
0:b1b901ae3696 | 36 | #endif |