aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSugandha Gupta <sugandha.gupta@ettus.com>2019-04-24 14:31:40 -0700
committermichael-west <michael.west@ettus.com>2019-05-21 17:20:42 -0700
commited2507a688d8d2e3aa6825f90ce29192d244d233 (patch)
tree9ada525e4ef0e09e9326e88c21aaeb8fd05a8f9d
parent3e82c285759dedc9355161f953f71f7c7ac11f6b (diff)
downloaduhd-ed2507a688d8d2e3aa6825f90ce29192d244d233.tar.gz
uhd-ed2507a688d8d2e3aa6825f90ce29192d244d233.tar.bz2
uhd-ed2507a688d8d2e3aa6825f90ce29192d244d233.zip
liberio: Release context holder on destruction of last liberio xport
This will make sure that the context holder for the liberio context is destroyed when the last liberio transport is destroyed, and not on termination of the program.
-rw-r--r--host/lib/transport/liberio_zero_copy.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/host/lib/transport/liberio_zero_copy.cpp b/host/lib/transport/liberio_zero_copy.cpp
index 989480382..15131910a 100644
--- a/host/lib/transport/liberio_zero_copy.cpp
+++ b/host/lib/transport/liberio_zero_copy.cpp
@@ -57,8 +57,6 @@ private:
liberio_ctx* _ctx;
};
-UHD_SINGLETON_FCN(liberio_context_holder, get_liberio_context_holder);
-
class liberio_zero_copy_msb : public virtual managed_send_buffer
{
public:
@@ -139,7 +137,15 @@ public:
UHD_ASSERT_THROW(xport_params.num_send_frames > 0);
UHD_ASSERT_THROW(xport_params.num_recv_frames > 0);
- liberio_ctx* ctx = get_liberio_context_holder().get();
+ {
+ std::lock_guard<std::mutex> _l(_context_lock);
+ if (!_ref_count) {
+ _context_holder = std::make_shared<liberio_context_holder>();
+ }
+
+ _ref_count++;
+ }
+ liberio_ctx* ctx = _context_holder->get();
/* we hold a reference, that we'd drop immediately after,
* so no requirement to get another one here ...
@@ -193,6 +199,13 @@ public:
{
liberio_chan_put(_tx_chan);
liberio_chan_put(_rx_chan);
+ {
+ std::lock_guard<std::mutex> _l(_context_lock);
+ _ref_count--;
+ if (!_ref_count) {
+ _context_holder.reset();
+ }
+ }
}
managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1)
@@ -245,8 +258,16 @@ private:
size_t _next_send_buff_index;
std::mutex _rx_mutex;
std::mutex _tx_mutex;
+
+ static std::mutex _context_lock;
+ static size_t _ref_count;
+ static std::shared_ptr<liberio_context_holder> _context_holder;
};
+std::mutex liberio_zero_copy_impl::_context_lock;
+size_t liberio_zero_copy_impl::_ref_count = 0;
+std::shared_ptr<liberio_context_holder> liberio_zero_copy_impl::_context_holder{};
+
liberio_zero_copy::sptr liberio_zero_copy::make(const std::string& tx_path,
const std::string& rx_path,
const zero_copy_xport_params& default_buff_args)