diff options
author | michael-west <michael.west@ettus.com> | 2014-03-07 13:23:00 -0800 |
---|---|---|
committer | michael-west <michael.west@ettus.com> | 2014-03-07 13:23:00 -0800 |
commit | a8d4649c4e95a5d8ccfe3c52fdbfc05c984f3acc (patch) | |
tree | 603d535d764e0850d7b99df3ab619daaaefe2f21 | |
parent | 973b47c48339dbae2e125a8c8d84ef67fedc4bdf (diff) | |
download | uhd-a8d4649c4e95a5d8ccfe3c52fdbfc05c984f3acc.tar.gz uhd-a8d4649c4e95a5d8ccfe3c52fdbfc05c984f3acc.tar.bz2 uhd-a8d4649c4e95a5d8ccfe3c52fdbfc05c984f3acc.zip |
Fix for BUG #386: RIO & UHD: Flush buffers smarter
- Updated flush algorithm to acquire and release all elements instead of 1 element at a time
-rw-r--r-- | host/lib/transport/nirio_zero_copy.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/host/lib/transport/nirio_zero_copy.cpp b/host/lib/transport/nirio_zero_copy.cpp index 7b1e32fe0..c3c8a9368 100644 --- a/host/lib/transport/nirio_zero_copy.cpp +++ b/host/lib/transport/nirio_zero_copy.cpp @@ -18,7 +18,6 @@ #include <uhd/transport/nirio_zero_copy.hpp> #include <stdio.h> #include <uhd/transport/nirio/nirio_fifo.h> -#include <uhd/transport/nirio/nirio_fifo.h> #include <uhd/transport/buffer_pool.hpp> #include <uhd/utils/msg.hpp> #include <uhd/utils/log.hpp> @@ -261,19 +260,27 @@ private: UHD_INLINE void _flush_rx_buff() { - nirio_status flush_status = 0; - while (nirio_status_not_fatal(flush_status)) { - static const size_t NUM_ELEMS_TO_FLUSH = 1; - static const uint32_t FLUSH_TIMEOUT_IN_MS = 0; - - fifo_data_t* flush_data_ptr = NULL; - size_t flush_elems_acquired = 0, flush_elems_remaining = 0; - flush_status = _recv_fifo->acquire( - flush_data_ptr, NUM_ELEMS_TO_FLUSH, FLUSH_TIMEOUT_IN_MS, - flush_elems_acquired, flush_elems_remaining); - if (nirio_status_not_fatal(flush_status)) { - _recv_fifo->release(flush_elems_acquired); - } + // acquire is called with 0 elements requested first to + // get the number of elements in the buffer and then + // repeatedly with the number of remaining elements + // until the buffer is empty + fifo_data_t* elems_buffer; + for (size_t num_elems_requested = 0, + num_elems_acquired = 0, + num_elems_remaining = 1; + num_elems_remaining; + num_elems_requested = num_elems_remaining) + { + nirio_status status = _recv_fifo->acquire( + elems_buffer, + num_elems_requested, + 0, // timeout + num_elems_acquired, + num_elems_remaining); + // throw excetption if status is fatal + nirio_status_to_exception(status, + "NI-RIO PCIe data transfer failed during flush."); + _recv_fifo->release(num_elems_acquired); } } |