forked from ARMmbed/mbed-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventLoop.cpp
49 lines (39 loc) · 882 Bytes
/
EventLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifdef MBED_CONF_RTOS_PRESENT
#include "EventLoop.h"
#include "events.h"
#include "rtos.h"
#include "mbed.h"
EventLoop::EventLoop(
osPriority priority,
unsigned event_size,
unsigned char *event_pointer,
uint32_t stack_size,
unsigned char *stack_pointer)
: EventQueue(event_size, event_pointer)
, _thread(priority, stack_size, stack_pointer)
, _running(false) {
}
EventLoop::~EventLoop() {
stop();
}
static void run(EventLoop *loop) {
loop->dispatch();
}
osStatus EventLoop::start() {
if (_running) {
return osOK;
}
osStatus status = _thread.start(this, run);
_running = (status == osOK);
return status;
}
osStatus EventLoop::stop() {
if (!_running) {
return osOK;
}
break_();
osStatus status = _thread.join();
_running = false;
return status;
}
#endif