mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-05-23 17:01:31 -04:00
Methods to peek and skip messages in queue.
Allows receiver to not consume a message until after it's handled. And that enables the transmitter to block until the queue is empty, knowing that when unblocked, all messages in queue have been handled.
This commit is contained in:
parent
c75c167c25
commit
8fde4972b4
2 changed files with 39 additions and 0 deletions
|
@ -47,6 +47,25 @@ public:
|
|||
return push(&message, sizeof(message));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool push_and_wait(const T& message) {
|
||||
const bool result = push(message);
|
||||
if( result ) {
|
||||
// TODO: More graceful method of waiting for empty? Maybe sleep for a bit?
|
||||
while( !is_empty() );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Message* peek(std::array<uint8_t, Message::MAX_SIZE>& buf) {
|
||||
Message* const p = reinterpret_cast<Message*>(buf.data());
|
||||
return fifo.peek_r(buf.data(), buf.size()) ? p : nullptr;
|
||||
}
|
||||
|
||||
bool skip() {
|
||||
return fifo.skip();
|
||||
}
|
||||
|
||||
Message* pop(std::array<uint8_t, Message::MAX_SIZE>& buf) {
|
||||
Message* const p = reinterpret_cast<Message*>(buf.data());
|
||||
return fifo.out_r(buf.data(), buf.size()) ? p : nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue