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

Commit

Permalink
Adopted equeue_break added to events
Browse files Browse the repository at this point in the history
  • Loading branch information
geky committed Jun 16, 2016
1 parent 9bdbb96 commit 1904552
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
27 changes: 3 additions & 24 deletions EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ EventLoop::~EventLoop() {
stop();
}

MBED_NORETURN static void run(EventLoop *loop) {
static void run(EventLoop *loop) {
loop->dispatch();
MBED_UNREACHABLE;
}

osStatus EventLoop::start() {
Expand All @@ -37,33 +36,13 @@ osStatus EventLoop::start() {
return status;
}


struct hcontext {
struct event e;
Semaphore halted;
};

MBED_NORETURN static void halt(void *p) {
Semaphore *halted = static_cast<Semaphore*>(p);
halted->release();
while (true) {
Thread::wait(osWaitForever);
}
}

osStatus EventLoop::stop() {
if (!_running) {
return osOK;
}

// Freeze the thread in a safe state
struct hcontext context = {{0}, Semaphore(0)};
event_delay(&context.halted, 0);
event_post(&_equeue, halt, &context.halted);
context.halted.wait();

// Kill the thread
osStatus status = _thread.terminate();
break_();
osStatus status = _thread.join();
_running = false;
return status;
}
Expand Down
4 changes: 4 additions & 0 deletions EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ void EventQueue::dispatch(int ms) {
return equeue_dispatch(&_equeue, ms);
}

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

unsigned EventQueue::get_tick() {
return events_tick();
}
Expand Down
2 changes: 2 additions & 0 deletions EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class EventQueue {


protected:
void break_();

struct equeue _equeue;

template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
Expand Down
2 changes: 1 addition & 1 deletion TESTS/events/queue/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void cancel_test2() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
//GREENTEA_SETUP(5, "default_auto");
GREENTEA_SETUP(20, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
2 changes: 1 addition & 1 deletion events-c.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/geky/events/#a9a60ed7021309876166159860966a6b9e83ae01
https://github.com/geky/events/#7383fd6f78be620ca01d91d23423870e79ea0622

0 comments on commit 1904552

Please sign in to comment.