Graceful shutdown running async jobs
Former-commit-id: 2ce5b94741d384b2dfd6d3b347fa1582cd45df8f
This commit is contained in:
parent
993359e1bb
commit
2db9eef2b1
@ -73,6 +73,18 @@ bool AsyncWorkQueue::removeClientAsyncWrites(client *c)
|
||||
return fFound;
|
||||
}
|
||||
|
||||
void AsyncWorkQueue::shutdown()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
serverAssert(!GlobalLocksAcquired());
|
||||
m_fQuitting = true;
|
||||
m_cvWakeup.notify_all();
|
||||
lock.unlock();
|
||||
|
||||
for (auto &thread : m_vecthreads)
|
||||
thread.join();
|
||||
}
|
||||
|
||||
void AsyncWorkQueue::abandonThreads()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
@ -34,5 +34,7 @@ public:
|
||||
void AddWorkFunction(std::function<void()> &&fnAsync, bool fHiPri = false);
|
||||
bool removeClientAsyncWrites(struct client *c);
|
||||
|
||||
void shutdown();
|
||||
|
||||
void abandonThreads();
|
||||
};
|
@ -4225,6 +4225,13 @@ int prepareForShutdown(int flags) {
|
||||
/* Close the listening sockets. Apparently this allows faster restarts. */
|
||||
closeListeningSockets(1);
|
||||
|
||||
if (g_pserver->asyncworkqueue)
|
||||
{
|
||||
aeReleaseLock();
|
||||
g_pserver->asyncworkqueue->shutdown();
|
||||
aeAcquireLock();
|
||||
}
|
||||
|
||||
for (int iel = 0; iel < cserver.cthreads; ++iel)
|
||||
{
|
||||
aePostFunction(g_pserver->rgthreadvar[iel].el, [iel]{
|
||||
|
Loading…
x
Reference in New Issue
Block a user