From 16bc247079adfadf95a90bc12a9e2c9063120766 Mon Sep 17 00:00:00 2001 From: Yakiv Huryk <62013282+Yakiv-Huryk@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:52:19 +0200 Subject: [PATCH 1/2] [tests] fix binary_data_get unit test (#841) fix incorrect sizeof() value Signed-off-by: Yakiv Huryk Co-authored-by: Prince Sunny --- tests/redis_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/redis_ut.cpp b/tests/redis_ut.cpp index c8532ff55..94684d7de 100644 --- a/tests/redis_ut.cpp +++ b/tests/redis_ut.cpp @@ -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 values_set = { From efbc27678751a9d74d46e98f87283ec71a761fc9 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox Date: Fri, 29 Dec 2023 08:56:39 +0200 Subject: [PATCH 2/2] Use selectable event to terminate logger thread --- common/logger.cpp | 12 +++++++++--- common/logger.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/logger.cpp b/common/logger.cpp index e2db4960d..54e519b90 100644 --- a/common/logger.cpp +++ b/common/logger.cpp @@ -44,7 +44,7 @@ void Logger::terminateSettingThread() if (m_settingThread) { - m_runSettingThread = false; + m_stopEvent->notify(); m_settingThread->join(); @@ -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)); } @@ -195,8 +195,9 @@ void Logger::settingThread() auto table = std::make_shared(&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; @@ -216,6 +217,11 @@ void Logger::settingThread() continue; } + if (selectable == m_stopEvent.get()) + { + break; + } + KeyOpFieldsValuesTuple koValues; SubscriberStateTable *subscriberStateTable = NULL; subscriberStateTable = dynamic_cast(selectable); diff --git a/common/logger.h b/common/logger.h index 27ad68a33..0a57f2f98 100644 --- a/common/logger.h +++ b/common/logger.h @@ -10,6 +10,7 @@ #include #include "concurrentmap.h" +#include "selectableevent.h" namespace swss { @@ -161,7 +162,7 @@ class Logger std::atomic m_output = { SWSS_SYSLOG }; std::unique_ptr m_settingThread; std::mutex m_mutex; - volatile bool m_runSettingThread = true; + std::unique_ptr m_stopEvent; }; }