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.
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
The events library requires a small porting layer:
- equeue_tick - monotonic counter
- equeue_mutex - non-recursive mutex
- equeue_sema - binary semaphore