From 0c7dca543a613b89fc68d1f2384992264c66cbbd Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 25 Oct 2018 23:54:04 +0200 Subject: [PATCH] [153-netconf-agent] Revamp the init thread --- src/bin/netconf/netconf.h | 5 ++++- src/bin/netconf/netconf_process.cc | 33 +++++++++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/bin/netconf/netconf.h b/src/bin/netconf/netconf.h index 7142d5aad5..c8d58d7382 100644 --- a/src/bin/netconf/netconf.h +++ b/src/bin/netconf/netconf.h @@ -53,7 +53,10 @@ public: /// Load Kea server configurations from YANG datastore. /// Subscribe changes in YANG datastore. /// - /// @param cfg_mgr The configuration manager. + /// If @c NetconfProcess::global_shut_down_flag becomes true + /// returns as soon as possible. + /// + /// @param cfg_mgr The configuration manager (can be null). void init(NetconfCfgMgrPtr cfg_mgr); /// @brief Clear. diff --git a/src/bin/netconf/netconf_process.cc b/src/bin/netconf/netconf_process.cc index c242f2ded6..9cef199909 100644 --- a/src/bin/netconf/netconf_process.cc +++ b/src/bin/netconf/netconf_process.cc @@ -46,19 +46,28 @@ NetconfProcess::run() { LOG_INFO(netconf_logger, NETCONF_STARTED).arg(VERSION); try { - // Initialize sysrepo. - if (!shouldShutdown()) { - agent_.initSysrepo(); - } - // Initialize netconf agent in a thread. - NetconfCfgMgrPtr cfg_mgr; - if (!shouldShutdown()) { - cfg_mgr = getNetconfCfgMgr(); - } - - // Initialize the agent in a thread. - Thread th([this, cfg_mgr]() { agent_.init(cfg_mgr); }); + Thread th([this]() { + if (shouldShutdown()) { + return; + } + // Initialize sysrepo. + agent_.initSysrepo(); + if (shouldShutdown()) { + return; + } + + // Get the configuration manager. + NetconfCfgMgrPtr cfg_mgr; + if (shouldShutdown()) { + return; + } else { + cfg_mgr = getNetconfCfgMgr(); + } + + // Call init. + agent_.init(cfg_mgr); + }); // Let's process incoming data or expiring timers in a loop until // shutdown condition is detected. -- 2.47.2