aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc/tx_async_msg_queue.cpp
diff options
context:
space:
mode:
authorCiro Nishiguchi <ciro.nishiguchi@ni.com>2019-08-08 10:25:20 -0500
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:36 -0800
commitbffef674fbbcd892967017e81515bb76e0b850b5 (patch)
tree8f56eb8548d0fb56094b555ae11d16eb61e6c381 /host/lib/rfnoc/tx_async_msg_queue.cpp
parent91e01c484475600fcd659bb433ab86efa5146426 (diff)
downloaduhd-bffef674fbbcd892967017e81515bb76e0b850b5.tar.gz
uhd-bffef674fbbcd892967017e81515bb76e0b850b5.tar.bz2
uhd-bffef674fbbcd892967017e81515bb76e0b850b5.zip
rfnoc: tx_streamer: add support for async messages
Add an async message queue that aggregates errors from multiple sources. Errors can come from the strs packets originating from the stream endpoint or from the radio block through control packets to the host.
Diffstat (limited to 'host/lib/rfnoc/tx_async_msg_queue.cpp')
-rw-r--r--host/lib/rfnoc/tx_async_msg_queue.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/host/lib/rfnoc/tx_async_msg_queue.cpp b/host/lib/rfnoc/tx_async_msg_queue.cpp
new file mode 100644
index 000000000..71a05074f
--- /dev/null
+++ b/host/lib/rfnoc/tx_async_msg_queue.cpp
@@ -0,0 +1,52 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhdlib/rfnoc/tx_async_msg_queue.hpp>
+#include <chrono>
+#include <thread>
+
+using namespace uhd;
+using namespace uhd::rfnoc;
+
+tx_async_msg_queue::tx_async_msg_queue(size_t capacity)
+ : _queue(capacity)
+{
+}
+
+bool tx_async_msg_queue::recv_async_msg(uhd::async_metadata_t& async_metadata,
+ int32_t timeout_ms)
+{
+ using namespace std::chrono;
+
+ if (timeout_ms == 0.0) {
+ return _queue.pop(async_metadata);
+ }
+
+ const auto end_time = steady_clock::now() + milliseconds(timeout_ms);
+
+ bool last_check = false;
+
+ while (true) {
+ if (_queue.pop(async_metadata)) {
+ return true;
+ }
+
+ if (steady_clock::now() > end_time) {
+ if (last_check) {
+ return false;
+ } else {
+ last_check = true;
+ }
+ }
+
+ std::this_thread::sleep_for(std::chrono::microseconds(100));
+ }
+}
+
+void tx_async_msg_queue::enqueue(const async_metadata_t& async_metadata)
+{
+ _queue.push(async_metadata);
+}