From 849525a1f3ad64c9b9a68389fefdeea3341076cb Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Thu, 24 Jan 2019 11:00:33 +0100 Subject: [PATCH] Initialize notification queue pointer before switch create (#411) * Initialize notification queue pointer before switch create * Fix spell mistake * Move start ntf thread after switch create and init pointer directly * Fix errors --- syncd/syncd.cpp | 4 ++++ syncd/syncd_notifications.cpp | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 19d34c39b3ed..6b15269f567b 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -3630,6 +3630,10 @@ int syncd_main(int argc, char **argv) onSyncdStart(options.startType == SAI_WARM_BOOT); SWSS_LOG_NOTICE("after onSyncdStart"); + // create notifications processing thread after we create_switch to + // make sure, we have switch_id translated to VID before we start + // processing possible quick fdb notifications, and pointer for + // notification queue is created before we create switch startNotificationsProcessingThread(); SWSS_LOG_NOTICE("syncd listening for events"); diff --git a/syncd/syncd_notifications.cpp b/syncd/syncd_notifications.cpp index 1af5b05f0e42..2b53828a6f63 100644 --- a/syncd/syncd_notifications.cpp +++ b/syncd/syncd_notifications.cpp @@ -458,6 +458,7 @@ std::condition_variable cv; class ntf_queue_t { public: + ntf_queue_t() { } bool enqueue(swss::KeyOpFieldsValuesTuple msg); bool tryDequeue(swss::KeyOpFieldsValuesTuple& msg); size_t queueStats() @@ -480,7 +481,15 @@ class ntf_queue_t const size_t limit = 300000; }; -static std::unique_ptr ntf_queue_hdlr; + +/* + * Make sure that notification queue pointer is populated before we start + * thread, and before we create_switch, since at switch_create we can start + * receiving fdb_notifications which will arrive on different thread and + * will call queueStats() when queue pointer could be null (this=0x0). + */ + +static std::unique_ptr ntf_queue_hdlr = std::unique_ptr(new ntf_queue_t); bool ntf_queue_t::tryDequeue( _Out_ swss::KeyOpFieldsValuesTuple &item) @@ -641,8 +650,6 @@ void ntf_process_function() { SWSS_LOG_ENTER(); - ntf_queue_hdlr = std::unique_ptr(new ntf_queue_t); - while (runThread) { cv.wait(ulock);