From 2d40c33b15ee91fdf5f0f7ca6987fe7dbf18205a Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 11 Sep 2019 19:47:21 -0700 Subject: rfnoc: rfnoc_graph: Safely deinit full graph on any kind of init error In the rfnoc_graph, we init blocks, GSM, motherboard controllers, and other things. Since any of these can potentially throw exceptions, we make sure to deinit those components that have already initialized properly before exiting. --- host/lib/rfnoc/rfnoc_graph.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'host/lib') diff --git a/host/lib/rfnoc/rfnoc_graph.cpp b/host/lib/rfnoc/rfnoc_graph.cpp index 60afbdad5..a6ec59d01 100644 --- a/host/lib/rfnoc/rfnoc_graph.cpp +++ b/host/lib/rfnoc/rfnoc_graph.cpp @@ -54,24 +54,24 @@ public: // Now initialize all subsystems: _init_mb_controllers(); _init_gsm(); // Graph Stream Manager - for (size_t mb_idx = 0; mb_idx < _num_mboards; ++mb_idx) { - try { - // If anything fails here, we immediately deinit all the other - // blocks to avoid any more fallout, then safely bring down the - // device. + try { + // If anything fails here, we immediately deinit all the other + // blocks to avoid any more fallout, then safely bring down the + // device. + for (size_t mb_idx = 0; mb_idx < _num_mboards; ++mb_idx) { _init_blocks(mb_idx, dev_addr); - } catch (...) { - _block_registry->shutdown(); - throw; } + UHD_LOG_TRACE(LOG_ID, "Initializing properties on all blocks..."); + _block_registry->init_props(); + _init_sep_map(); + _init_static_connections(); + _init_mbc(); + // Start with time set to zero, but don't complain if sync fails + rfnoc_graph_impl::synchronize_devices(uhd::time_spec_t(0.0), true); + } catch (...) { + _block_registry->shutdown(); + throw; } - UHD_LOG_TRACE(LOG_ID, "Initializing properties on all blocks..."); - _block_registry->init_props(); - _init_sep_map(); - _init_static_connections(); - _init_mbc(); - // Start with time set to zero, but don't complain if sync fails - rfnoc_graph_impl::synchronize_devices(uhd::time_spec_t(0.0), true); } catch (const std::exception& ex) { UHD_LOG_ERROR(LOG_ID, "Caught exception while initializing graph: " << ex.what()); throw uhd::runtime_error("Failure to create rfnoc_graph."); -- cgit v1.2.3