diff options
author | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-10-19 14:05:34 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-10-22 15:01:15 -0500 |
commit | 24154b99a70ca59c8f91f6506370244ee68a0365 (patch) | |
tree | e76e9b7dd010e779544459447d098ee15230a119 | |
parent | 5ea43897419aac8db824944abc764868232b45af (diff) | |
download | uhd-24154b99a70ca59c8f91f6506370244ee68a0365.tar.gz uhd-24154b99a70ca59c8f91f6506370244ee68a0365.tar.bz2 uhd-24154b99a70ca59c8f91f6506370244ee68a0365.zip |
graph: Serialize all graph-related functions
This commit expands the scope of the former _release_mutex, renaming it
_graph_mutex and ensuring that all graph modification functions are
serialized against each other. This ensures that callers to graph_t's
public functions are always operating on a coherent view of the
underlying BGL graph object.
-rw-r--r-- | host/lib/include/uhdlib/rfnoc/graph.hpp | 4 | ||||
-rw-r--r-- | host/lib/rfnoc/graph.cpp | 17 |
2 files changed, 13 insertions, 8 deletions
diff --git a/host/lib/include/uhdlib/rfnoc/graph.hpp b/host/lib/include/uhdlib/rfnoc/graph.hpp index fa9921cf6..288de63ce 100644 --- a/host/lib/include/uhdlib/rfnoc/graph.hpp +++ b/host/lib/include/uhdlib/rfnoc/graph.hpp @@ -298,8 +298,8 @@ private: //! Flag to ensure serialized handling of actions std::atomic_flag _action_handling_ongoing; - //! Changes to the release/commit state of the graph are locked with this mutex - std::recursive_mutex _release_mutex; + //! Changes to the state of the graph are locked with this mutex + std::recursive_mutex _graph_mutex; //! This counter gets decremented everytime commit() is called. When zero, // the graph is committed. diff --git a/host/lib/rfnoc/graph.cpp b/host/lib/rfnoc/graph.cpp index 2edf591b3..a26ed33fc 100644 --- a/host/lib/rfnoc/graph.cpp +++ b/host/lib/rfnoc/graph.cpp @@ -69,6 +69,8 @@ private: *****************************************************************************/ void graph_t::connect(node_ref_t src_node, node_ref_t dst_node, graph_edge_t edge_info) { + std::lock_guard<std::recursive_mutex> l(_graph_mutex); + node_accessor_t node_accessor{}; UHD_LOG_TRACE(LOG_ID, "Connecting block " << src_node->get_unique_id() << ":" << edge_info.src_port @@ -179,6 +181,8 @@ void graph_t::connect(node_ref_t src_node, node_ref_t dst_node, graph_edge_t edg void graph_t::disconnect(node_ref_t src_node, node_ref_t dst_node, graph_edge_t edge_info) { + std::lock_guard<std::recursive_mutex> l(_graph_mutex); + // Find vertex descriptor if (_node_map.count(src_node) == 0 && _node_map.count(dst_node) == 0) { return; @@ -210,12 +214,13 @@ void graph_t::disconnect(node_ref_t src_node, node_ref_t dst_node, graph_edge_t void graph_t::remove(node_ref_t node) { + std::lock_guard<std::recursive_mutex> l(_graph_mutex); _remove_node(node); } void graph_t::commit() { - std::lock_guard<std::recursive_mutex> l(_release_mutex); + std::lock_guard<std::recursive_mutex> l(_graph_mutex); if (_release_count) { _release_count--; } @@ -227,14 +232,14 @@ void graph_t::commit() void graph_t::release() { - std::lock_guard<std::recursive_mutex> l(_release_mutex); + std::lock_guard<std::recursive_mutex> l(_graph_mutex); UHD_LOG_TRACE(LOG_ID, "graph::release() => " << _release_count); _release_count++; } void graph_t::shutdown() { - std::lock_guard<std::recursive_mutex> l(_release_mutex); + std::lock_guard<std::recursive_mutex> l(_graph_mutex); UHD_LOG_TRACE(LOG_ID, "graph::shutdown()"); _shutdown = true; _release_count = std::numeric_limits<size_t>::max(); @@ -270,7 +275,7 @@ void graph_t::resolve_all_properties( // method to make sure that a) different threads can't interfere with each // other, and b) that we don't release the graph while this method is still // running. - std::lock_guard<std::recursive_mutex> l(_release_mutex); + std::lock_guard<std::recursive_mutex> l(_graph_mutex); if (_shutdown) { return; } @@ -428,7 +433,7 @@ void graph_t::enqueue_action( // method to make sure that we don't release the graph while this method is // still running. // It also prevents a different thread from throwing in their own actions. - std::lock_guard<std::recursive_mutex> release_lock(_release_mutex); + std::lock_guard<std::recursive_mutex> release_lock(_graph_mutex); if (_shutdown) { return; } @@ -505,7 +510,7 @@ void graph_t::enqueue_action( // Release the action handling flag _action_handling_ongoing.clear(); - // Now, the _release_mutex is released, and someone else can start sending + // Now, the _graph_mutex is released, and someone else can start sending // actions. } |