Skip to content

Commit 849525a

Browse files
kcudniklguohan
authored andcommitted
Initialize notification queue pointer before switch create (sonic-net#411)
* Initialize notification queue pointer before switch create * Fix spell mistake * Move start ntf thread after switch create and init pointer directly * Fix errors
1 parent 02d92f1 commit 849525a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

syncd/syncd.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,10 @@ int syncd_main(int argc, char **argv)
36303630
onSyncdStart(options.startType == SAI_WARM_BOOT);
36313631
SWSS_LOG_NOTICE("after onSyncdStart");
36323632

3633+
// create notifications processing thread after we create_switch to
3634+
// make sure, we have switch_id translated to VID before we start
3635+
// processing possible quick fdb notifications, and pointer for
3636+
// notification queue is created before we create switch
36333637
startNotificationsProcessingThread();
36343638

36353639
SWSS_LOG_NOTICE("syncd listening for events");

syncd/syncd_notifications.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ std::condition_variable cv;
458458
class ntf_queue_t
459459
{
460460
public:
461+
ntf_queue_t() { }
461462
bool enqueue(swss::KeyOpFieldsValuesTuple msg);
462463
bool tryDequeue(swss::KeyOpFieldsValuesTuple& msg);
463464
size_t queueStats()
@@ -480,7 +481,15 @@ class ntf_queue_t
480481
const size_t limit = 300000;
481482
};
482483

483-
static std::unique_ptr<ntf_queue_t> ntf_queue_hdlr;
484+
485+
/*
486+
* Make sure that notification queue pointer is populated before we start
487+
* thread, and before we create_switch, since at switch_create we can start
488+
* receiving fdb_notifications which will arrive on different thread and
489+
* will call queueStats() when queue pointer could be null (this=0x0).
490+
*/
491+
492+
static std::unique_ptr<ntf_queue_t> ntf_queue_hdlr = std::unique_ptr<ntf_queue_t>(new ntf_queue_t);
484493

485494
bool ntf_queue_t::tryDequeue(
486495
_Out_ swss::KeyOpFieldsValuesTuple &item)
@@ -641,8 +650,6 @@ void ntf_process_function()
641650
{
642651
SWSS_LOG_ENTER();
643652

644-
ntf_queue_hdlr = std::unique_ptr<ntf_queue_t>(new ntf_queue_t);
645-
646653
while (runThread)
647654
{
648655
cv.wait(ulock);

0 commit comments

Comments
 (0)