2023-08-27 23:35:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
|
|
|
|
class ControlledQueue {
|
|
|
|
public:
|
2023-09-03 23:30:07 +00:00
|
|
|
/*
|
|
|
|
Default constructo added for default initialization in std::array. If used, it's necessary to call the init function afterwards.
|
|
|
|
*/
|
|
|
|
ControlledQueue() {;}
|
2023-08-27 23:35:30 +00:00
|
|
|
ControlledQueue(uint32_t maxSize, int timeoutMicroseconds);
|
|
|
|
|
2023-09-03 23:30:07 +00:00
|
|
|
void init(uint32_t maxSize, int timeoutMicroseconds);
|
|
|
|
void put(uint32_t word);
|
|
|
|
uint32_t get();
|
|
|
|
// Simple wrapper to check queue size
|
|
|
|
int size() { return m_queue.size(); }
|
|
|
|
|
|
|
|
// Simple wrapper to see wether the queue is empty
|
2023-08-27 23:35:30 +00:00
|
|
|
bool empty() { return m_queue.empty(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::mutex m_mtx;
|
|
|
|
std::condition_variable m_cv;
|
|
|
|
uint32_t m_maxSize;
|
2023-09-03 23:30:07 +00:00
|
|
|
std::queue<uint32_t> m_queue;
|
2023-08-27 23:35:30 +00:00
|
|
|
int m_timeoutMicroseconds;
|
|
|
|
|
|
|
|
};
|