Move message handling loops to MessageQueue.

This commit is contained in:
Jared Boone 2016-02-27 21:07:11 -08:00
parent eb294c8e1c
commit bf348cf30a
3 changed files with 14 additions and 8 deletions

View File

@ -134,10 +134,9 @@ void EventDispatcher::dispatch(const eventmask_t events) {
}
void EventDispatcher::handle_application_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = shared_memory.application_queue.pop(message_buffer)) {
shared_memory.application_queue.handle([](Message* const message) {
message_map().send(message);
}
});
}
void EventDispatcher::handle_rtc_tick() {

View File

@ -86,11 +86,9 @@ void EventDispatcher::dispatch(const eventmask_t events) {
}
void EventDispatcher::handle_baseband_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = shared_memory.baseband_queue.peek(message_buffer)) {
on_message(message);
shared_memory.baseband_queue.skip();
}
shared_memory.baseband_queue.handle([this](Message* const message) {
this->on_message(message);
});
}
void EventDispatcher::on_message(const Message* const message) {

View File

@ -82,6 +82,15 @@ public:
return fifo.is_empty();
}
template<typename HandlerFn>
void handle(HandlerFn handler) {
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = peek(message_buffer)) {
handler(message);
skip();
}
}
private:
FIFO<uint8_t> fifo;
Mutex mutex_write;