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:
2:11cda6bead99
Parent:
1:2202c19570e5
Child:
10:62767e708bb6
--- a/EventQueue.h	Wed Apr 20 12:40:18 2016 -0500
+++ b/EventQueue.h	Wed Apr 20 14:15:54 2016 -0500
@@ -5,31 +5,55 @@
 #ifndef EVENT_QUEUE_H
 #define EVENT_QUEUE_H
 
+#include "mbed.h"
+
 
 /** Flexible queue for managing events
  */
 class EventQueue {
 public:
+    /** Create an event queue
+     */
+    EventQueue();
+
     /** Dispatch pending events
      *  @param ms       Time to wait for events in milliseconds,
      *                  0 indicates to return immediately if no events are pending
      */
     void dispatch(int ms=-1);
 
+    /** Get current tick of the event queue
+     *  @return         Number of milliseconds since the queue was instantiated,
+     *                  this count intentionally overflows to 0 after 2^32-1
+     */
+    unsigned get_tick();
+
 private:
     struct event {
         struct event *volatile next;
+        unsigned target;
+        bool registered;
+
+        int delay;
+        int period;
+
         void (*callback)(void *);
         void *data;
     };
 
-    void event_register(struct event *event);
+    void event_register(struct event *event, int ms);
     void event_unregister(struct event *event);
 
+    void tick();
+    void wakeup();
+
+    struct event *volatile _queue;
+    unsigned _tick;
+    mbed::Ticker _ticker;
+    mbed::Timer _timer;
+
     template <typename F>
     friend class Event;
-
-    struct event *volatile _queue;
 };