Note! This project has moved to github.com/armmbed/mbed-events

Dependents:   SimpleHTTPExample

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.

Committer:
Christopher Haster
Date:
Fri Apr 22 02:06:42 2016 -0500
Revision:
8:3c2a014bd907
Child:
11:6721568592e5
Added thread based EventLoop under EVENTS_NO_RTOS define

Who changed what in which revision?

UserRevisionLine numberNew 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 8:3c2a014bd907 12 class EventLoop : public EventQueue {
Christopher Haster 8:3c2a014bd907 13 public:
Christopher Haster 8:3c2a014bd907 14 /** Create an event loop without starting execution
Christopher Haster 8:3c2a014bd907 15 */
Christopher Haster 8:3c2a014bd907 16 EventLoop();
Christopher Haster 8:3c2a014bd907 17
Christopher Haster 8:3c2a014bd907 18 /** Create an event loop running in a dedicated thread
Christopher Haster 8:3c2a014bd907 19 * @param priority Initial priority of the thread
Christopher Haster 8:3c2a014bd907 20 * (default: osPriorityNormal)
Christopher Haster 8:3c2a014bd907 21 * @param stack_size Stack size (in bytes) requirements for the thread
Christopher Haster 8:3c2a014bd907 22 * (default: DEFAULT_STACK_SIZE)
Christopher Haster 8:3c2a014bd907 23 * @param stack_pointer Pointer to stack area to be used by the thread
Christopher Haster 8:3c2a014bd907 24 * (default: NULL)
Christopher Haster 8:3c2a014bd907 25 */
Christopher Haster 8:3c2a014bd907 26 EventLoop(bool start,
Christopher Haster 8:3c2a014bd907 27 osPriority priority=osPriorityNormal,
Christopher Haster 8:3c2a014bd907 28 uint32_t stack_size=DEFAULT_STACK_SIZE,
Christopher Haster 8:3c2a014bd907 29 unsigned char *stack_pointer=NULL);
Christopher Haster 8:3c2a014bd907 30
Christopher Haster 8:3c2a014bd907 31 /** Clean up event loop
Christopher Haster 8:3c2a014bd907 32 */
Christopher Haster 8:3c2a014bd907 33 ~EventLoop();
Christopher Haster 8:3c2a014bd907 34
Christopher Haster 8:3c2a014bd907 35 /** Starts an event loop running in a dedicated thread
Christopher Haster 8:3c2a014bd907 36 * @param priority Initial priority of the thread
Christopher Haster 8:3c2a014bd907 37 * (default: osPriorityNormal)
Christopher Haster 8:3c2a014bd907 38 * @param stack_size Stack size (in bytes) requirements for the thread
Christopher Haster 8:3c2a014bd907 39 * (default: DEFAULT_STACK_SIZE)
Christopher Haster 8:3c2a014bd907 40 * @param stack_pointer Pointer to stack area to be used by the thread
Christopher Haster 8:3c2a014bd907 41 * (default: NULL)
Christopher Haster 8:3c2a014bd907 42 */
Christopher Haster 8:3c2a014bd907 43 void start(osPriority priority=osPriorityNormal,
Christopher Haster 8:3c2a014bd907 44 uint32_t stack_size=DEFAULT_STACK_SIZE,
Christopher Haster 8:3c2a014bd907 45 unsigned char *stack_pointer=NULL);
Christopher Haster 8:3c2a014bd907 46
Christopher Haster 8:3c2a014bd907 47 /** Stops an event loop cleanly, waiting for any currently executing events
Christopher Haster 8:3c2a014bd907 48 */
Christopher Haster 8:3c2a014bd907 49 void stop();
Christopher Haster 8:3c2a014bd907 50
Christopher Haster 8:3c2a014bd907 51 private:
Christopher Haster 8:3c2a014bd907 52 static void run(const void *p);
Christopher Haster 8:3c2a014bd907 53
Christopher Haster 8:3c2a014bd907 54 bool _running;
Christopher Haster 8:3c2a014bd907 55 rtos::Thread *_thread;
Christopher Haster 8:3c2a014bd907 56 };
Christopher Haster 8:3c2a014bd907 57
Christopher Haster 8:3c2a014bd907 58 #endif
Christopher Haster 8:3c2a014bd907 59 #endif