Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Rename underlying C library to equeue #10

Merged
merged 3 commits into from
Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mbedignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
events-c/tests/
equeue/tests/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script:
- cd events-c
- cd equeue

# Strict compilation of library
- CFLAGS='-pedantic -Werror' make
Expand Down
2 changes: 1 addition & 1 deletion EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void EventQueue::break_() {
}

unsigned EventQueue::get_tick() {
return events_tick();
return equeue_tick();
}

void EventQueue::cancel(int id) {
Expand Down
18 changes: 9 additions & 9 deletions EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef EVENT_QUEUE_H
#define EVENT_QUEUE_H

#include "events-c/events.h"
#include "equeue/equeue.h"
#include "Callback.h"
#include <cstddef>
#include <new>
Expand All @@ -28,8 +28,8 @@ namespace events {
* Minimum size of an event
* This size fits a Callback<void()> at minimum
*/
#undef EVENTS_EVENT_SIZE
#define EVENTS_EVENT_SIZE (sizeof(struct event) + sizeof(void*) + sizeof(mbed::Callback<void()>))
#define EVENTS_EVENT_SIZE \
(EQUEUE_EVENT_SIZE - 2*sizeof(void*) + sizeof(mbed::Callback<void()>))

/** DEFAULT_QUEUE_SIZE
* default size of buffer for events
Expand Down Expand Up @@ -95,7 +95,7 @@ class EventQueue {
}

F *e = new (p) F(f);
event_dtor(e, &EventQueue::dtor<F>);
equeue_event_dtor(e, &EventQueue::dtor<F>);
return equeue_post(&_equeue, &EventQueue::call<F>, e);
}

Expand Down Expand Up @@ -140,8 +140,8 @@ class EventQueue {
}

F *e = new (p) F(f);
event_delay(e, ms);
event_dtor(e, &EventQueue::dtor<F>);
equeue_event_delay(e, ms);
equeue_event_dtor(e, &EventQueue::dtor<F>);
return equeue_post(&_equeue, &EventQueue::call<F>, e);
}

Expand Down Expand Up @@ -186,9 +186,9 @@ class EventQueue {
}

F *e = new (p) F(f);
event_delay(e, ms);
event_period(e, ms);
event_dtor(e, &EventQueue::dtor<F>);
equeue_event_delay(e, ms);
equeue_event_period(e, ms);
equeue_event_dtor(e, &EventQueue::dtor<F>);
return equeue_post(&_equeue, &EventQueue::call<F>, e);
}

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion events-c/Makefile → equeue/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET = libevents.a
TARGET = libequeue.a

CC = gcc
AR = ar
Expand Down
29 changes: 14 additions & 15 deletions events-c/README.md → equeue/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
## Events ##
## The equeue library ##

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

``` c
#include "events.h"
#include "equeue.h"
#include <stdio.h>

void print(void *s) {
Expand All @@ -15,12 +14,12 @@ void print(void *s) {
int main() {
// creates a queue with space for 32 basic events
equeue_t queue;
equeue_create(&queue, 32*EVENTS_EVENT_SIZE);
equeue_create(&queue, 32*EQUEUE_EVENT_SIZE);

// events are simple callbacks
equeue_call(&queue, print, "called immediately");
equeue_call_in(&queue, print, "called in 2 seconds", 2000);
equeue_call_every(&queue, print, "called every 1 seconds", 1000);
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);
Expand All @@ -32,14 +31,14 @@ int main() {
}
```

The events library can be used for normal event loops, however it also
supports multithreaded environments. More information on the idea
behind composable event loops
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](https://gist.github.com/geky/4969d940f1bd5596bdc10e79093e2553).

## Tests ##

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

Runtime tests are located in [tests.c](tests/tests.c):

Expand All @@ -63,6 +62,6 @@ cat results.txt | make prof
## Porting ##

The events library requires a small porting layer:
- [events_tick](events_tick.h) - monotonic counter
- [events_mutex](events_mutex.h) - non-recursive mutex
- [events_sema](events_sema.h) - binary semaphore
- [equeue_tick](equeue_tick.h) - monotonic counter
- [equeue_mutex](equeue_mutex.h) - non-recursive mutex
- [equeue_sema](equeue_sema.h) - binary semaphore
Loading