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.

EventQueue.h

Committer:
Christopher Haster
Date:
2016-04-20
Revision:
1:2202c19570e5
Parent:
0:b1b901ae3696
Child:
2:11cda6bead99

File content as of revision 1:2202c19570e5:

/*  EventQueue
 *
 *  Flexible queue for managing events
 */
#ifndef EVENT_QUEUE_H
#define EVENT_QUEUE_H


/** Flexible queue for managing events
 */
class EventQueue {
public:
    /** 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);

private:
    struct event {
        struct event *volatile next;
        void (*callback)(void *);
        void *data;
    };

    void event_register(struct event *event);
    void event_unregister(struct event *event);

    template <typename F>
    friend class Event;

    struct event *volatile _queue;
};


#endif