Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use selectable event to terminate logger thread #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};

}
4 changes: 2 additions & 2 deletions tests/redis_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,8 @@ TEST(Table, binary_data_get)
DBConnector db("TEST_DB", 0, true);
Table table(&db, "binary_data");

const char* bindata1 = "\x11\x00\x22\x33\x44";
const char* bindata2 = "\x11\x22\x33\x00\x44";
const char bindata1[] = "\x11\x00\x22\x33\x44";
const char bindata2[] = "\x11\x22\x33\x00\x44";
auto v1 = std::string(bindata1, sizeof(bindata1));
auto v2 = std::string(bindata2, sizeof(bindata2));
vector<FieldValueTuple> values_set = {
Expand Down