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

Commit 1904552

Browse files
committed
Adopted equeue_break added to events
1 parent 9bdbb96 commit 1904552

File tree

5 files changed

+11
-26
lines changed

5 files changed

+11
-26
lines changed

EventLoop.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ EventLoop::~EventLoop() {
2222
stop();
2323
}
2424

25-
MBED_NORETURN static void run(EventLoop *loop) {
25+
static void run(EventLoop *loop) {
2626
loop->dispatch();
27-
MBED_UNREACHABLE;
2827
}
2928

3029
osStatus EventLoop::start() {
@@ -37,33 +36,13 @@ osStatus EventLoop::start() {
3736
return status;
3837
}
3938

40-
41-
struct hcontext {
42-
struct event e;
43-
Semaphore halted;
44-
};
45-
46-
MBED_NORETURN static void halt(void *p) {
47-
Semaphore *halted = static_cast<Semaphore*>(p);
48-
halted->release();
49-
while (true) {
50-
Thread::wait(osWaitForever);
51-
}
52-
}
53-
5439
osStatus EventLoop::stop() {
5540
if (!_running) {
5641
return osOK;
5742
}
5843

59-
// Freeze the thread in a safe state
60-
struct hcontext context = {{0}, Semaphore(0)};
61-
event_delay(&context.halted, 0);
62-
event_post(&_equeue, halt, &context.halted);
63-
context.halted.wait();
64-
65-
// Kill the thread
66-
osStatus status = _thread.terminate();
44+
break_();
45+
osStatus status = _thread.join();
6746
_running = false;
6847
return status;
6948
}

EventQueue.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ void EventQueue::dispatch(int ms) {
2626
return equeue_dispatch(&_equeue, ms);
2727
}
2828

29+
void EventQueue::break_() {
30+
return equeue_break(&_equeue);
31+
}
32+
2933
unsigned EventQueue::get_tick() {
3034
return events_tick();
3135
}

EventQueue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ class EventQueue {
208208

209209

210210
protected:
211+
void break_();
212+
211213
struct equeue _equeue;
212214

213215
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>

TESTS/events/queue/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void cancel_test2() {
201201

202202
// Test setup
203203
utest::v1::status_t test_setup(const size_t number_of_cases) {
204-
//GREENTEA_SETUP(5, "default_auto");
204+
GREENTEA_SETUP(20, "default_auto");
205205
return verbose_test_setup_handler(number_of_cases);
206206
}
207207

events-c.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/geky/events/#a9a60ed7021309876166159860966a6b9e83ae01
1+
https://github.com/geky/events/#7383fd6f78be620ca01d91d23423870e79ea0622

0 commit comments

Comments
 (0)