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

Remove the EventLoop class #14

Merged
merged 1 commit into from
Aug 10, 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
49 changes: 0 additions & 49 deletions EventLoop.cpp

This file was deleted.

74 changes: 0 additions & 74 deletions EventLoop.h

This file was deleted.

4 changes: 2 additions & 2 deletions EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ void EventQueue::dispatch(int ms) {
return equeue_dispatch(&_equeue, ms);
}

void EventQueue::break_() {
void EventQueue::break_dispatch() {
return equeue_break(&_equeue);
}

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

Expand Down
24 changes: 15 additions & 9 deletions EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ namespace events {
#define EVENTS_EVENT_SIZE \
(EQUEUE_EVENT_SIZE - 2*sizeof(void*) + sizeof(mbed::Callback<void()>))

/** DEFAULT_QUEUE_SIZE
* default size of buffer for events
/** EVENTS_QUEUE_SIZE
* Default size of buffer for events
*/
#define DEFAULT_QUEUE_SIZE (32*EVENTS_EVENT_SIZE)
#define EVENTS_QUEUE_SIZE (32*EVENTS_EVENT_SIZE)


/** EventQueue
Expand All @@ -46,11 +46,11 @@ class EventQueue {
/** Create an event queue
*
* @param queue_size Size of buffer to use for events
* (default: DEFAULT_QUEUE_SIZE)
* (default: EVENTS_QUEUE_SIZE)
* @param queue_pointer Pointer to memory region to use for events
* (default: NULL)
*/
EventQueue(unsigned queue_size=DEFAULT_QUEUE_SIZE,
EventQueue(unsigned queue_size=EVENTS_QUEUE_SIZE,
unsigned char *queue_pointer=NULL);

/** Destroy an event queue
Expand All @@ -63,13 +63,21 @@ class EventQueue {
* value will dispatch events forever
* (default: -1)
*/
void dispatch(int ms=-1);
void dispatch(int ms);
void dispatch() { dispatch(-1); }

/** Break out of a running event loop
*
* Forces the specified event queue's dispatch loop to terminate. Pending
* events may finish executing, but no new events will be executed.
*/
void break_dispatch();

/* Monotonic counter for the event queue
* @return A monotonically incrementing counter in milliseconds
* this count intentionally overflows to 0 after 2^32-1
*/
unsigned get_tick();
unsigned tick();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be advertised somewhere that get_tick has been renamed in tick.

Copy link
Contributor Author

@geky geky Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do, probably should have been a separate pr


/** Cancel events that are in flight
*
Expand Down Expand Up @@ -241,8 +249,6 @@ class EventQueue {
}

protected:
void break_();

struct equeue _equeue;
mbed::Callback<void(int)> _update;

Expand Down
64 changes: 0 additions & 64 deletions TESTS/events/queue/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,40 +102,6 @@ void call_every_test() {
queue.dispatch(N*100);
}

#ifdef MBED_CONF_RTOS_PRESENT
void event_loop_test1() {
EventLoop loop;
osStatus status = loop.start();
TEST_ASSERT_EQUAL(osOK, status);

touched = false;
loop.call(func0);
Thread::yield();
TEST_ASSERT(touched);

status = loop.stop();
TEST_ASSERT_EQUAL(osOK, status);
}

template <int N>
void event_loop_test2() {
EventLoop loop(osPriorityHigh);
osStatus status = loop.start();
TEST_ASSERT_EQUAL(osOK, status);

Timer tickers[N];

for (int i = 0; i < N; i++) {
tickers[i].start();
loop.call_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
Thread::yield();
wait_ms(75);
}

wait_ms(N*100);
}
#endif

struct big { char data[4096]; } big;

void allocate_failure_test1() {
Expand Down Expand Up @@ -176,28 +142,6 @@ void cancel_test1() {
queue.dispatch(0);
}

#ifdef MBED_CONF_RTOS_PRESENT
template <int N>
void cancel_test2() {
EventLoop loop;
osStatus status = loop.start();
TEST_ASSERT_EQUAL(osOK, status);

int ids[N];

for (int i = 0; i < N; i++) {
ids[i] = loop.call_in(1000, no);
}

for (int i = N-1; i >= 0; i--) {
loop.cancel(ids[i]);
}

status = loop.stop();
TEST_ASSERT_EQUAL(osOK, status);
}
#endif


// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
Expand All @@ -216,18 +160,10 @@ const Case cases[] = {
Case("Testing call_in", call_in_test<20>),
Case("Testing call_every", call_every_test<20>),

#ifdef MBED_CONF_RTOS_PRESENT
Case("Testing event loop 1", event_loop_test1),
Case("Testing event loop 2", event_loop_test2<20>),
#endif

Case("Testing allocate failure 1", allocate_failure_test1),
Case("Testing allocate failure 2", allocate_failure_test2),

Case("Testing event cancel 1", cancel_test1<20>),
#ifdef MBED_CONF_RTOS_PRESENT
Case("Testing event cancel 2", cancel_test2<20>),
#endif
};

Specification specification(test_setup, cases);
Expand Down
1 change: 0 additions & 1 deletion mbed_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#ifdef __cplusplus

#include "EventQueue.h"
#include "EventLoop.h"

using namespace events;

Expand Down