Skip to content

Commit a9a2602

Browse files
authored
Merge branch 'master' into smart_switch_db
2 parents bd95490 + 2711f6f commit a9a2602

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

common/logger.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ void Logger::terminateSettingThread()
4444

4545
if (m_settingThread)
4646
{
47-
m_runSettingThread = false;
47+
m_stopEvent->notify();
4848

4949
m_settingThread->join();
5050

5151
m_settingThread = nullptr;
52+
53+
m_stopEvent = nullptr;
5254
}
5355
}
5456

5557
void Logger::restartSettingThread()
5658
{
5759
terminateSettingThread();
5860

59-
m_runSettingThread = true;
61+
m_stopEvent = std::make_unique<SelectableEvent>(0);
6062

6163
m_settingThread.reset(new std::thread(&Logger::settingThread, this));
6264
}
@@ -195,8 +197,9 @@ void Logger::settingThread()
195197
auto table = std::make_shared<SubscriberStateTable>(&db, CFG_LOGGER_TABLE_NAME);
196198
selectables.emplace(CFG_LOGGER_TABLE_NAME, table);
197199
select.addSelectable(table.get());
200+
select.addSelectable(m_stopEvent.get());
198201

199-
while (m_runSettingThread)
202+
while (1)
200203
{
201204

202205
Selectable *selectable = nullptr;
@@ -216,6 +219,11 @@ void Logger::settingThread()
216219
continue;
217220
}
218221

222+
if (selectable == m_stopEvent.get())
223+
{
224+
break;
225+
}
226+
219227
KeyOpFieldsValuesTuple koValues;
220228
SubscriberStateTable *subscriberStateTable = NULL;
221229
subscriberStateTable = dynamic_cast<SubscriberStateTable *>(selectable);

common/logger.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <functional>
1111

1212
#include "concurrentmap.h"
13+
#include "selectableevent.h"
1314

1415
namespace swss {
1516

@@ -161,7 +162,7 @@ class Logger
161162
std::atomic<Output> m_output = { SWSS_SYSLOG };
162163
std::unique_ptr<std::thread> m_settingThread;
163164
std::mutex m_mutex;
164-
volatile bool m_runSettingThread = true;
165+
std::unique_ptr<SelectableEvent> m_stopEvent;
165166
};
166167

167168
}

0 commit comments

Comments
 (0)