Skip to content

Commit a1f8709

Browse files
committed
feat(DataHandlerSync): variable queue size
1 parent bd24abd commit a1f8709

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

inc/udmaio/ConcurrentQueue.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#pragma once
1313

14+
#include <algorithm>
1415
#include <chrono>
1516
#include <condition_variable>
1617
#include <mutex>
@@ -51,7 +52,7 @@ class ConcurrentQueue {
5152
/// @param item Element to push to the queue
5253
void push(T item) {
5354
std::unique_lock<std::mutex> lock(_mutex);
54-
if (_queue.size() >= MAX_ELEMS) {
55+
if (_queue.size() >= _max_elems) {
5556
lock.unlock();
5657
throw std::runtime_error("libudmaio: ConcurrentQueue full");
5758
}
@@ -66,15 +67,15 @@ class ConcurrentQueue {
6667
_cond.notify_one();
6768
}
6869

69-
ConcurrentQueue() = default;
70+
ConcurrentQueue(size_t max_elems = 64) : _max_elems{max_elems} {}
7071
ConcurrentQueue(const ConcurrentQueue&) = delete;
7172
ConcurrentQueue& operator=(const ConcurrentQueue&) = delete;
7273

7374
private:
7475
std::queue<T> _queue;
7576
std::mutex _mutex;
7677
std::condition_variable _cond;
77-
constexpr static size_t MAX_ELEMS = 64;
78+
size_t _max_elems;
7879
bool _abort = false;
7980
};
8081

inc/udmaio/DataHandlerSync.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#pragma once
1313

14+
#include <cstddef>
15+
#include <iterator>
1416
#include <optional>
1517
#include <thread>
1618

@@ -25,7 +27,14 @@ class DataHandlerSync : public DataHandlerAbstract {
2527
std::optional<std::thread> _ioThread; ///< I/O thread
2628

2729
public:
28-
using DataHandlerAbstract::DataHandlerAbstract;
30+
explicit DataHandlerSync(std::string name,
31+
UioAxiDmaIf& dma,
32+
UioMemSgdma& desc,
33+
DmaBufferAbstract& mem,
34+
bool receive_packets = true,
35+
size_t queue_size = 64)
36+
: DataHandlerAbstract{name, dma, desc, mem, receive_packets}, _queue{queue_size} {}
37+
2938
virtual ~DataHandlerSync();
3039

3140
/// Run the data reception

0 commit comments

Comments
 (0)