aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorAndrew Lynch <andrew.lynch@ni.com>2020-01-17 13:58:58 -0600
committeratrnati <54334261+atrnati@users.noreply.github.com>2020-02-26 07:54:23 -0600
commit3822b21b6e8824ec8f652ce5091294b30bde1c5c (patch)
tree12e0346ccc8ec0763b8c5e157d4b7b877231a728 /host/lib
parentc42776f97b126b71a13bb8339988cda09203f589 (diff)
downloaduhd-3822b21b6e8824ec8f652ce5091294b30bde1c5c.tar.gz
uhd-3822b21b6e8824ec8f652ce5091294b30bde1c5c.tar.bz2
uhd-3822b21b6e8824ec8f652ce5091294b30bde1c5c.zip
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.
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/rfnoc/rfnoc_graph.cpp21
1 files changed, 20 insertions, 1 deletions
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<rfnoc_graph_impl>(dev, device_addr);
+ static std::mutex _map_mutex;
+ static std::map<std::weak_ptr<rfnoc_device>,
+ std::weak_ptr<rfnoc_graph>,
+ std::owner_less<std::weak_ptr<rfnoc_device>>>
+ dev_to_graph;
+ rfnoc_graph::sptr graph;
+
+ // Check if a graph was already created for this device
+ std::lock_guard<std::mutex> 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<rfnoc_graph_impl>(dev, device_addr);
+ dev_to_graph[dev] = graph;
+ return graph;
}
}}} /* namespace uhd::rfnoc::detail */