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

Commit

Permalink
Merge commit da0e401 into mbed-events/events-c
Browse files Browse the repository at this point in the history
da0e401 Updated README.md with information on tests/profiling
dcb356a Cleaned up makefile
ba0c701 Added rudimentary profiling
5ac2216 Added c99 pedantic test
312f9c2 Removed non-c99 conformant code
057e2a1 Defined behaviour of negative delays to discard event
  • Loading branch information
geky committed Jul 14, 2016
2 parents ff8ad3b + da0e401 commit a132285
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 26 deletions.
13 changes: 13 additions & 0 deletions events-c/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
script:
# Strict compilation of library
- CFLAGS='-pedantic -Werror' make

# Runtime tests
- make test

# Relative profiling with current master
- if ( git clone https://github.com/geky/events tests/master &&
make -s -C tests/master prof | tee tests/results.txt ) ;
then
cat tests/results.txt | make prof ;
else
make prof ;
fi
24 changes: 11 additions & 13 deletions events-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
ASM := $(SRC:.c=.s)

TESTS = tests/tests
TSRC += $(wildcard tests/*.c)
TOBJ := $(TSRC:.c=.o)
TDEP := $(TSRC:.c=.d)

ifdef DEBUG
CFLAGS += -O0 -g3 -DMU_DEBUG
CFLAGS += -fkeep-inline-functions
CFLAGS += -O0 -g3
else
CFLAGS += -O2
endif
Expand All @@ -25,17 +19,21 @@ CFLAGS += -m$(WORD)
endif
CFLAGS += -I.
CFLAGS += -std=c99
CFLAGS += -Wall -Winline
CFLAGS += -Wall
CFLAGS += -D_XOPEN_SOURCE=500

LFLAGS += -lpthread


all: $(TARGET)

test: $(TOBJ) $(OBJ)
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $(TESTS)
$(TESTS)
test: tests/tests.o $(OBJ)
$(CC) $(CFLAGS) $^ $(LFLAGS) -o tests/tests
tests/tests

prof: tests/prof.o $(OBJ)
$(CC) $(CFLAGS) $^ $(LFLAGS) -o tests/prof
tests/prof

asm: $(ASM)

Expand All @@ -55,8 +53,8 @@ size: $(OBJ)

clean:
rm -f $(TARGET)
rm -f $(TESTS)
rm -f $(TOBJ) $(TDEP)
rm -f tests/tests tests/tests.o tests/tests.d
rm -f tests/prof tests/prof.o tests/prof.d
rm -f $(OBJ)
rm -f $(DEP)
rm -f $(ASM)
35 changes: 27 additions & 8 deletions events-c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,32 @@ supports multithreaded environments. More information on the idea
behind composable event loops
[here](https://gist.github.com/geky/4969d940f1bd5596bdc10e79093e2553).
## Porting ##
## Tests ##
The events library uses a set of local tests based on the posix implementation.
Runtime tests are located in [tests.c](tests/tests.c):
``` bash
make test
```

Profiling tests based on rdtsc are located in [prof.c](tests/prof.c):

The events library only requires the following:
- monotonic counter
- non-recursive mutex
- binary semaphore
``` bash
make prof
```

To make profiling results more tangible, the profiler also supports percentage
comparison with previous runs:
``` bash
make prof | tee results.txt
cat results.txt | make prof
```

## Porting ##

Supported implementations are hosted as branches on this repo:
- Posix
- mbed
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
15 changes: 10 additions & 5 deletions events-c/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ static inline int equeue_tickdiff(unsigned a, unsigned b) {
return (int)(a - b);
}

static int equeue_enqueue(equeue_t *q, struct event *e, int ms) {
e->target = events_tick() + (unsigned)ms;
static void equeue_enqueue(equeue_t *q, struct event *e, unsigned ms) {
e->target = events_tick() + ms;

struct event **p = &q->queue;
while (*p && equeue_tickdiff((*p)->target, e->target) <= 0) {
Expand All @@ -167,8 +167,6 @@ static int equeue_enqueue(equeue_t *q, struct event *e, int ms) {

e->next = *p;
*p = e;

return e->id;
}

static struct event *equeue_dequeue(equeue_t *q, int id) {
Expand All @@ -184,9 +182,16 @@ static struct event *equeue_dequeue(equeue_t *q, int id) {
}

static int equeue_post(equeue_t *q, struct event *e, int ms) {
int id = e->id;
if (ms < 0) {
event_dealloc(q, e+1);
return id;
}

events_mutex_lock(&q->queuelock);
int id = equeue_enqueue(q, e, ms);
equeue_enqueue(q, e, ms);
events_mutex_unlock(&q->queuelock);

events_sema_release(&q->eventsema);
return id;
}
Expand Down
Loading

0 comments on commit a132285

Please sign in to comment.