mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Wrap MessageQueue.push() with mutex.
This addresses issue #61, occasional FIFO/data corruption. With the mutex, any thread on one core can write to the FIFO. But still, only one thread on one core should read from the FIFO.
This commit is contained in:
parent
7937ea7327
commit
035ec84f04
@ -30,9 +30,15 @@
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#include <ch.h>
|
||||
|
||||
template<size_t K>
|
||||
class MessageQueue {
|
||||
public:
|
||||
MessageQueue() {
|
||||
chMtxInit(&mutex_write);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool push(const T& message) {
|
||||
static_assert(sizeof(T) <= Message::MAX_SIZE, "Message::MAX_SIZE too small for message type");
|
||||
@ -55,9 +61,13 @@ public:
|
||||
|
||||
private:
|
||||
FIFO<uint8_t, K> fifo;
|
||||
Mutex mutex_write;
|
||||
|
||||
bool push(const void* const buf, const size_t len) {
|
||||
chMtxLock(&mutex_write);
|
||||
const auto result = fifo.in_r(buf, len);
|
||||
chMtxUnlock();
|
||||
|
||||
const bool success = (result == len);
|
||||
if( success ) {
|
||||
signal();
|
||||
|
Loading…
Reference in New Issue
Block a user