Skip to content

Commit

Permalink
Use selectable event to terminate logger thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox committed Dec 29, 2023
1 parent b2480ad commit d2b2433
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void Logger::terminateSettingThread()

if (m_settingThread)
{
m_runSettingThread = false;
m_stopEvent->notify();

m_settingThread->join();

Expand All @@ -56,7 +56,7 @@ void Logger::restartSettingThread()
{
terminateSettingThread();

m_runSettingThread = true;
m_stopEvent.reset(new SelectableEvent(0));

m_settingThread.reset(new std::thread(&Logger::settingThread, this));
}
Expand Down Expand Up @@ -195,8 +195,9 @@ void Logger::settingThread()
auto table = std::make_shared<SubscriberStateTable>(&db, CFG_LOGGER_TABLE_NAME);
selectables.emplace(CFG_LOGGER_TABLE_NAME, table);
select.addSelectable(table.get());
select.addSelectable(m_stopEvent.get());

while (m_runSettingThread)
while (1)
{

Selectable *selectable = nullptr;
Expand All @@ -216,6 +217,11 @@ void Logger::settingThread()
continue;
}

if (selectable == m_stopEvent.get())
{
break;
}

KeyOpFieldsValuesTuple koValues;
SubscriberStateTable *subscriberStateTable = NULL;
subscriberStateTable = dynamic_cast<SubscriberStateTable *>(selectable);
Expand Down
3 changes: 2 additions & 1 deletion common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <functional>

#include "concurrentmap.h"
#include "selectableevent.h"

namespace swss {

Expand Down Expand Up @@ -161,7 +162,7 @@ class Logger
std::atomic<Output> m_output = { SWSS_SYSLOG };
std::unique_ptr<std::thread> m_settingThread;
std::mutex m_mutex;
volatile bool m_runSettingThread = true;
std::unique_ptr<SelectableEvent> m_stopEvent;
};

}

0 comments on commit d2b2433

Please sign in to comment.