Skip to content

Commit

Permalink
Initialize notification queue pointer before switch create (sonic-net…
Browse files Browse the repository at this point in the history
…#411)

* Initialize notification queue pointer before switch create

* Fix spell mistake

* Move start ntf thread after switch create and init pointer directly

* Fix errors
  • Loading branch information
kcudnik authored and lguohan committed Jan 24, 2019
1 parent 02d92f1 commit 849525a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 10 additions & 3 deletions syncd/syncd_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -480,7 +481,15 @@ class ntf_queue_t
const size_t limit = 300000;
};

static std::unique_ptr<ntf_queue_t> 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_t> ntf_queue_hdlr = std::unique_ptr<ntf_queue_t>(new ntf_queue_t);

bool ntf_queue_t::tryDequeue(
_Out_ swss::KeyOpFieldsValuesTuple &item)
Expand Down Expand Up @@ -641,8 +650,6 @@ void ntf_process_function()
{
SWSS_LOG_ENTER();

ntf_queue_hdlr = std::unique_ptr<ntf_queue_t>(new ntf_queue_t);

while (runThread)
{
cv.wait(ulock);
Expand Down

0 comments on commit 849525a

Please sign in to comment.