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.

Revision:
14:5abf2ccf2dbf
Parent:
8:3c2a014bd907
Child:
16:ff5d48fcce1b
--- a/EventLoop.cpp	Fri Apr 22 22:32:35 2016 -0500
+++ b/EventLoop.cpp	Tue May 10 07:51:44 2016 -0500
@@ -4,18 +4,32 @@
 
 using namespace rtos;
 
-EventLoop::EventLoop() {
+EventLoop::EventLoop(osPriority priority,
+                     unsigned event_count,
+                     unsigned event_context,
+                     uint32_t stack_size,
+                     unsigned char *stack_pointer)
+        : EventQueue(event_count, event_context) {
     _running = false;
+    _priority = priority;
+    _stack_size = stack_size;
+    _stack_pointer = stack_pointer;
 }
 
 EventLoop::EventLoop(bool start,
                      osPriority priority,
+                     unsigned event_count,
+                     unsigned event_context,
                      uint32_t stack_size,
-                     unsigned char *stack_pointer) {
+                     unsigned char *stack_pointer)
+        : EventQueue(event_count, event_context) {
     _running = false;
+    _priority = priority;
+    _stack_size = stack_size;
+    _stack_pointer = stack_pointer;
 
     if (start) {
-        EventLoop::start(priority, stack_size, stack_pointer);
+        EventLoop::start();
     }
 }
 
@@ -23,15 +37,13 @@
     stop();
 }
 
-void EventLoop::start(osPriority priority,
-                      uint32_t stack_size,
-                      unsigned char *stack_pointer) {
+void EventLoop::start() {
     if (_running) {
         return;
     }
 
     _running = true;
-    _thread = new Thread(run, this, priority, stack_size, stack_pointer);
+    _thread = new Thread(run, this, _priority, _stack_size, _stack_pointer);
 }
 
 void EventLoop::stop() {