Last active
July 13, 2018 18:09
-
-
Save giuliomoro/18d69ad146c975b2d24c6ef0b2694a7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pass audio data between two RtThreads bi-directionally. | |
// This should create a slave RtThread. | |
// The master thread should be a RtThread. | |
// The master thread starts a transmission; | |
// the slave thread should be woken up when there is data available, | |
// process the data, and send data back to the master thread | |
// Uni-directional RT-safe-queue. | |
// A light wrapper around __wrap_mq_... | |
class DataFifo | |
{ | |
int create(std::string& name, size_t queueSize, bool blocking = 0); | |
int send(char* buf, size_t size); | |
int receive(char* buf, size_t maxSize); | |
private: | |
// add your stuff here | |
}; | |
// Usage: | |
DataFifo dataFifoToSlave; | |
DataFifo dataFifoToMaster; | |
otherThread() | |
{ | |
dataFifoToSlave.receive(); // block | |
/// process | |
dataFifoToMaster.send(); | |
} | |
setup() | |
{ | |
dataFifoToSlave.create(blocksize); | |
dataFifoToMaster.create(blocksize); | |
} | |
render() | |
{ | |
dataFifoToSlave.send(); | |
dataFifoToMaster.receive(); // non block | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment