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:
16:ff5d48fcce1b
Parent:
14:5abf2ccf2dbf
Child:
20:2f9d9c53a5af
--- a/EventLoop.cpp	Tue May 10 09:23:27 2016 -0500
+++ b/EventLoop.cpp	Mon Apr 18 09:47:21 2016 -0500
@@ -1,8 +1,6 @@
 #include "EventLoop.h"
+#include "rtos.h"
 
-#ifndef EVENTS_NO_RTOS
-
-using namespace rtos;
 
 EventLoop::EventLoop(osPriority priority,
                      unsigned event_count,
@@ -37,29 +35,43 @@
     stop();
 }
 
-void EventLoop::start() {
+osStatus EventLoop::start() {
     if (_running) {
-        return;
+        return osOK;
     }
 
     _running = true;
     _thread = new Thread(run, this, _priority, _stack_size, _stack_pointer);
+    if (!_thread) {
+        return osErrorNoMemory;
+    }
+
+    return osOK;
 }
 
-void EventLoop::stop() {
+osStatus EventLoop::stop() {
     if (!_running) {
-        return;
+        return osOK;
     }
 
     Thread *thread = _thread;
     _thread = 0;
 
     _running = false;
-    while (thread->get_state() != Thread::Inactive) {
-        Thread::yield();
+    while (true) {
+        uint8_t state = thread->get_state();
+        if (state == Thread::Inactive || state == osErrorParameter) {
+            break;
+        }
+
+        osStatus status = Thread::yield();
+        if (status != osOK) {
+            break;
+        }
     }
 
     delete thread;
+    return osOK;
 }
 
 void EventLoop::run(const void *p) {
@@ -71,4 +83,3 @@
     }
 }
 
-#endif