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.
Diff: EventLoop.h
- Revision:
- 8:3c2a014bd907
- Child:
- 11:6721568592e5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EventLoop.h Fri Apr 22 02:06:42 2016 -0500 @@ -0,0 +1,59 @@ +/* EventLoop + * + * EventQueue wrapped in a thread + */ +#ifndef EVENT_LOOP_H +#define EVENT_LOOP_H +#ifndef EVENTS_NO_RTOS + +#include "EventQueue.h" +#include "Thread.h" + +class EventLoop : public EventQueue { +public: + /** Create an event loop without starting execution + */ + EventLoop(); + + /** Create an event loop running in a dedicated thread + * @param priority Initial priority of the thread + * (default: osPriorityNormal) + * @param stack_size Stack size (in bytes) requirements for the thread + * (default: DEFAULT_STACK_SIZE) + * @param stack_pointer Pointer to stack area to be used by the thread + * (default: NULL) + */ + EventLoop(bool start, + osPriority priority=osPriorityNormal, + uint32_t stack_size=DEFAULT_STACK_SIZE, + unsigned char *stack_pointer=NULL); + + /** Clean up event loop + */ + ~EventLoop(); + + /** Starts an event loop running in a dedicated thread + * @param priority Initial priority of the thread + * (default: osPriorityNormal) + * @param stack_size Stack size (in bytes) requirements for the thread + * (default: DEFAULT_STACK_SIZE) + * @param stack_pointer Pointer to stack area to be used by the thread + * (default: NULL) + */ + void start(osPriority priority=osPriorityNormal, + uint32_t stack_size=DEFAULT_STACK_SIZE, + unsigned char *stack_pointer=NULL); + + /** Stops an event loop cleanly, waiting for any currently executing events + */ + void stop(); + +private: + static void run(const void *p); + + bool _running; + rtos::Thread *_thread; +}; + +#endif +#endif