From 4ef45eed56a4ec34c225d2a37cc02efc2131033b Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Wed, 23 May 2018 00:12:01 +0000 Subject: [PATCH] Merge pull request #321 from yxieca/syncd [syncd] stop notification thread before calling remove_switch() [notif] don't detach syncd notification thread So that we could join() it at shutdown time. Signed-off-by: Ying Xie [flex counter] remove all flex counters before exiting syncd Remove the early quit Add log enter to removeAllCounters() --- syncd/syncd.cpp | 7 +++++-- syncd/syncd_flex_counter.cpp | 7 +++++++ syncd/syncd_flex_counter.h | 1 + syncd/syncd_notifications.cpp | 2 -- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 8b29f9bece6e..b90d85b6ef2a 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -3449,6 +3449,11 @@ int syncd_main(int argc, char **argv) #endif + FlexCounter::removeAllCounters(); + + // Stop notification thread before removing switch + stopNotificationsProcessingThread(); + status = sai_switch_api->remove_switch(gSwitchId); if (status != SAI_STATUS_SUCCESS) { @@ -3465,8 +3470,6 @@ int syncd_main(int argc, char **argv) SWSS_LOG_ERROR("failed to uninitialize api: %s", sai_serialize_status(status).c_str()); } - stopNotificationsProcessingThread(); - SWSS_LOG_NOTICE("uninitialize finished"); return EXIT_SUCCESS; diff --git a/syncd/syncd_flex_counter.cpp b/syncd/syncd_flex_counter.cpp index bdca4971070e..2419a7531df7 100644 --- a/syncd/syncd_flex_counter.cpp +++ b/syncd/syncd_flex_counter.cpp @@ -331,6 +331,13 @@ void FlexCounter::removeCounterPlugin( } } +void FlexCounter::removeAllCounters() +{ + SWSS_LOG_ENTER(); + + g_flex_counters_map.clear(); +} + FlexCounter::~FlexCounter(void) { diff --git a/syncd/syncd_flex_counter.h b/syncd/syncd_flex_counter.h index 1771feb2ae38..111fc8260851 100644 --- a/syncd/syncd_flex_counter.h +++ b/syncd/syncd_flex_counter.h @@ -51,6 +51,7 @@ class FlexCounter _In_ std::string instanceId); static void removeCounterPlugin( _In_ std::string instanceId); + static void removeAllCounters(); FlexCounter( _In_ const FlexCounter&) = delete; diff --git a/syncd/syncd_notifications.cpp b/syncd/syncd_notifications.cpp index 7bc8ee16161f..e4958e819602 100644 --- a/syncd/syncd_notifications.cpp +++ b/syncd/syncd_notifications.cpp @@ -559,8 +559,6 @@ void startNotificationsProcessingThread() runThread = true; ntf_process_thread = std::make_shared(ntf_process_function); - - ntf_process_thread->detach(); } void stopNotificationsProcessingThread()