Skip to content

geky/mbed

Repository files navigation

The equeue library

The equeue library provides a composable event queue implementation that acts as a drop in scheduler and event framework.

#include "equeue.h"
#include <stdio.h>

void print(void *s) {
    puts((const char *)s);
}

int main() {
    // creates a queue with space for 32 basic events
    equeue_t queue;
    equeue_create(&queue, 32*EQUEUE_EVENT_SIZE);

    // events are simple callbacks
    equeue_call(&queue, print, "called immediately");
    equeue_call_in(&queue, 2000, print, "called in 2 seconds");
    equeue_call_every(&queue, 1000, print, "called every 1 seconds");

    // events are executed when dispatch is called
    equeue_dispatch(&queue, 3000);

    print("called after 3 seconds");

    // dispatch can be called in an infinite loop
    equeue_dispatch(&queue, -1);
}

The equeue library can be used for a normal event loops, however it also supports composition and multithreaded environments. More information on the idea behind composable event loops here.

Tests

The equeue library uses a set of local tests based on the posix implementation.

Runtime tests are located in tests.c:

make test

Profiling tests based on rdtsc are located in prof.c:

make prof

To make profiling results more tangible, the profiler also supports percentage comparison with previous runs:

make prof | tee results.txt
cat results.txt | make prof

Porting

The events library requires a small porting layer:

About

mbed libraries and tools (Classic). For mbed OS, look here: https://www.mbed.com/en/development/software/mbed-os/

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 91.2%
  • C++ 4.5%
  • Assembly 3.2%
  • HTML 0.9%
  • Objective-C 0.1%
  • Makefile 0.1%