Skip to content

Commit f430b9c

Browse files
committed
Add a StoppableWaitGroup, and join it on #Stop(), to:
ApiListener CheckerComponent ExternalCommandListener LivestatusListener
1 parent 263fa98 commit f430b9c

File tree

8 files changed

+14
-0
lines changed

8 files changed

+14
-0
lines changed

lib/checker/checkercomponent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void CheckerComponent::Stop(bool runtimeRemoved)
8181
m_CV.notify_all();
8282
}
8383

84+
m_WaitGroup->Join();
8485
m_ResultTimer->Stop(true);
8586
m_Thread.join();
8687

lib/checker/checkercomponent.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "base/configobject.hpp"
99
#include "base/timer.hpp"
1010
#include "base/utility.hpp"
11+
#include "base/wait-group.hpp"
1112
#include <boost/multi_index_container.hpp>
1213
#include <boost/multi_index/ordered_index.hpp>
1314
#include <boost/multi_index/key_extractors.hpp>
@@ -77,6 +78,7 @@ class CheckerComponent final : public ObjectImpl<CheckerComponent>
7778
CheckableSet m_IdleCheckables;
7879
CheckableSet m_PendingCheckables;
7980

81+
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
8082
Timer::Ptr m_ResultTimer;
8183

8284
void CheckThreadProc();

lib/compat/externalcommandlistener.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ void ExternalCommandListener::Start(bool runtimeCreated)
5050
*/
5151
void ExternalCommandListener::Stop(bool runtimeRemoved)
5252
{
53+
m_WaitGroup->Join();
54+
5355
Log(LogInformation, "ExternalCommandListener")
5456
<< "'" << GetName() << "' stopped.";
5557

lib/compat/externalcommandlistener.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "compat/externalcommandlistener-ti.hpp"
77
#include "base/objectlock.hpp"
8+
#include "base/wait-group.hpp"
89
#include "base/timer.hpp"
910
#include "base/utility.hpp"
1011
#include <thread>
@@ -29,6 +30,8 @@ class ExternalCommandListener final : public ObjectImpl<ExternalCommandListener>
2930
void Stop(bool runtimeRemoved) override;
3031

3132
private:
33+
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
34+
3235
#ifndef _WIN32
3336
std::thread m_CommandThread;
3437

lib/livestatus/livestatuslistener.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void LivestatusListener::Stop(bool runtimeRemoved)
112112
<< "'" << GetName() << "' stopped.";
113113

114114
m_Listener->Close();
115+
m_WaitGroup->Join();
115116

116117
if (m_Thread.joinable())
117118
m_Thread.join();

lib/livestatus/livestatuslistener.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "livestatus/livestatuslistener-ti.hpp"
88
#include "livestatus/livestatusquery.hpp"
99
#include "base/socket.hpp"
10+
#include "base/wait-group.hpp"
1011
#include <thread>
1112

1213
using namespace icinga;
@@ -40,6 +41,7 @@ class LivestatusListener final : public ObjectImpl<LivestatusListener>
4041

4142
Socket::Ptr m_Listener;
4243
std::thread m_Thread;
44+
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
4345
};
4446

4547
}

lib/remote/apilistener.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ void ApiListener::Stop(bool runtimeDeleted)
368368
m_Timer->Stop(true);
369369
m_RenewOwnCertTimer->Stop(true);
370370

371+
m_WaitGroup->Join();
371372
ObjectImpl<ApiListener>::Stop(runtimeDeleted);
372373

373374
Log(LogInformation, "ApiListener")

lib/remote/apilistener.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "base/tcpsocket.hpp"
1717
#include "base/tlsstream.hpp"
1818
#include "base/threadpool.hpp"
19+
#include "base/wait-group.hpp"
1920
#include <atomic>
2021
#include <boost/asio/io_context.hpp>
2122
#include <boost/asio/ip/tcp.hpp>
@@ -177,6 +178,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
177178
Timer::Ptr m_RenewOwnCertTimer;
178179

179180
Endpoint::Ptr m_LocalEndpoint;
181+
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();
180182

181183
static ApiListener::Ptr m_Instance;
182184
static std::atomic<bool> m_UpdatedObjectAuthority;

0 commit comments

Comments
 (0)