From 3822b21b6e8824ec8f652ce5091294b30bde1c5c Mon Sep 17 00:00:00 2001 From: Andrew Lynch Date: Fri, 17 Jan 2020 13:58:58 -0600 Subject: rfnoc: Reuse the graph object Keep a reference to the graph object so that when a new multi_usrp is opened to the same device, the same graph is also used. --- host/lib/rfnoc/rfnoc_graph.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'host/lib') diff --git a/host/lib/rfnoc/rfnoc_graph.cpp b/host/lib/rfnoc/rfnoc_graph.cpp index 32a9b0071..9cb9edfe8 100644 --- a/host/lib/rfnoc/rfnoc_graph.cpp +++ b/host/lib/rfnoc/rfnoc_graph.cpp @@ -908,7 +908,26 @@ namespace uhd { namespace rfnoc { namespace detail { rfnoc_graph::sptr make_rfnoc_graph( detail::rfnoc_device::sptr dev, const uhd::device_addr_t& device_addr) { - return std::make_shared(dev, device_addr); + static std::mutex _map_mutex; + static std::map, + std::weak_ptr, + std::owner_less>> + dev_to_graph; + rfnoc_graph::sptr graph; + + // Check if a graph was already created for this device + std::lock_guard lock(_map_mutex); + if (dev_to_graph.count(dev) and not dev_to_graph[dev].expired()) { + graph = dev_to_graph[dev].lock(); + if (graph != nullptr) { + return graph; + } + } + + // Create a new graph + graph = std::make_shared(dev, device_addr); + dev_to_graph[dev] = graph; + return graph; } }}} /* namespace uhd::rfnoc::detail */ -- cgit v1.2.3