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.
EventLoop.h@11:6721568592e5, 2016-04-22 (annotated)
- Committer:
- Christopher Haster
- Date:
- Fri Apr 22 20:57:16 2016 -0500
- Revision:
- 11:6721568592e5
- Parent:
- 8:3c2a014bd907
- Child:
- 14:5abf2ccf2dbf
Fix documentation of EventLoop
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
8:3c2a014bd907 | 1 | /* EventLoop |
Christopher Haster |
8:3c2a014bd907 | 2 | * |
Christopher Haster |
8:3c2a014bd907 | 3 | * EventQueue wrapped in a thread |
Christopher Haster |
8:3c2a014bd907 | 4 | */ |
Christopher Haster |
8:3c2a014bd907 | 5 | #ifndef EVENT_LOOP_H |
Christopher Haster |
8:3c2a014bd907 | 6 | #define EVENT_LOOP_H |
Christopher Haster |
8:3c2a014bd907 | 7 | #ifndef EVENTS_NO_RTOS |
Christopher Haster |
8:3c2a014bd907 | 8 | |
Christopher Haster |
8:3c2a014bd907 | 9 | #include "EventQueue.h" |
Christopher Haster |
8:3c2a014bd907 | 10 | #include "Thread.h" |
Christopher Haster |
8:3c2a014bd907 | 11 | |
Christopher Haster |
11:6721568592e5 | 12 | /** Managed queue coupled with its own thread |
Christopher Haster |
11:6721568592e5 | 13 | */ |
Christopher Haster |
8:3c2a014bd907 | 14 | class EventLoop : public EventQueue { |
Christopher Haster |
8:3c2a014bd907 | 15 | public: |
Christopher Haster |
8:3c2a014bd907 | 16 | /** Create an event loop without starting execution |
Christopher Haster |
8:3c2a014bd907 | 17 | */ |
Christopher Haster |
8:3c2a014bd907 | 18 | EventLoop(); |
Christopher Haster |
8:3c2a014bd907 | 19 | |
Christopher Haster |
8:3c2a014bd907 | 20 | /** Create an event loop running in a dedicated thread |
Christopher Haster |
8:3c2a014bd907 | 21 | * @param priority Initial priority of the thread |
Christopher Haster |
8:3c2a014bd907 | 22 | * (default: osPriorityNormal) |
Christopher Haster |
8:3c2a014bd907 | 23 | * @param stack_size Stack size (in bytes) requirements for the thread |
Christopher Haster |
8:3c2a014bd907 | 24 | * (default: DEFAULT_STACK_SIZE) |
Christopher Haster |
8:3c2a014bd907 | 25 | * @param stack_pointer Pointer to stack area to be used by the thread |
Christopher Haster |
8:3c2a014bd907 | 26 | * (default: NULL) |
Christopher Haster |
8:3c2a014bd907 | 27 | */ |
Christopher Haster |
8:3c2a014bd907 | 28 | EventLoop(bool start, |
Christopher Haster |
8:3c2a014bd907 | 29 | osPriority priority=osPriorityNormal, |
Christopher Haster |
8:3c2a014bd907 | 30 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Christopher Haster |
8:3c2a014bd907 | 31 | unsigned char *stack_pointer=NULL); |
Christopher Haster |
8:3c2a014bd907 | 32 | |
Christopher Haster |
8:3c2a014bd907 | 33 | /** Clean up event loop |
Christopher Haster |
8:3c2a014bd907 | 34 | */ |
Christopher Haster |
8:3c2a014bd907 | 35 | ~EventLoop(); |
Christopher Haster |
8:3c2a014bd907 | 36 | |
Christopher Haster |
8:3c2a014bd907 | 37 | /** Starts an event loop running in a dedicated thread |
Christopher Haster |
8:3c2a014bd907 | 38 | * @param priority Initial priority of the thread |
Christopher Haster |
8:3c2a014bd907 | 39 | * (default: osPriorityNormal) |
Christopher Haster |
8:3c2a014bd907 | 40 | * @param stack_size Stack size (in bytes) requirements for the thread |
Christopher Haster |
8:3c2a014bd907 | 41 | * (default: DEFAULT_STACK_SIZE) |
Christopher Haster |
8:3c2a014bd907 | 42 | * @param stack_pointer Pointer to stack area to be used by the thread |
Christopher Haster |
8:3c2a014bd907 | 43 | * (default: NULL) |
Christopher Haster |
8:3c2a014bd907 | 44 | */ |
Christopher Haster |
8:3c2a014bd907 | 45 | void start(osPriority priority=osPriorityNormal, |
Christopher Haster |
8:3c2a014bd907 | 46 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Christopher Haster |
8:3c2a014bd907 | 47 | unsigned char *stack_pointer=NULL); |
Christopher Haster |
8:3c2a014bd907 | 48 | |
Christopher Haster |
8:3c2a014bd907 | 49 | /** Stops an event loop cleanly, waiting for any currently executing events |
Christopher Haster |
8:3c2a014bd907 | 50 | */ |
Christopher Haster |
8:3c2a014bd907 | 51 | void stop(); |
Christopher Haster |
8:3c2a014bd907 | 52 | |
Christopher Haster |
8:3c2a014bd907 | 53 | private: |
Christopher Haster |
8:3c2a014bd907 | 54 | static void run(const void *p); |
Christopher Haster |
8:3c2a014bd907 | 55 | |
Christopher Haster |
8:3c2a014bd907 | 56 | bool _running; |
Christopher Haster |
8:3c2a014bd907 | 57 | rtos::Thread *_thread; |
Christopher Haster |
8:3c2a014bd907 | 58 | }; |
Christopher Haster |
8:3c2a014bd907 | 59 | |
Christopher Haster |
8:3c2a014bd907 | 60 | #endif |
Christopher Haster |
8:3c2a014bd907 | 61 | #endif |