Eliminate unnecessary global locks

Former-commit-id: 8f924ed0979f3cf7cd290395d1b1eec358979325
This commit is contained in:
John Sully 2021-05-31 01:14:28 +00:00
parent a2010f17b8
commit ac49c7158c

View File

@ -18,9 +18,9 @@ void AsyncWorkQueue::WorkerThreadMain()
vars.clients_pending_asyncwrite = listCreate(); vars.clients_pending_asyncwrite = listCreate();
aeAcquireLock(); m_mutex.lock();
m_vecpthreadVars.push_back(&vars); m_vecpthreadVars.push_back(&vars);
aeReleaseLock(); m_mutex.unlock();
while (!m_fQuitting) while (!m_fQuitting)
{ {
@ -42,9 +42,11 @@ void AsyncWorkQueue::WorkerThreadMain()
lock.unlock(); lock.unlock();
serverTL->gcEpoch = g_pserver->garbageCollector.startEpoch(); serverTL->gcEpoch = g_pserver->garbageCollector.startEpoch();
aeAcquireLock(); if (listLength(serverTL->clients_pending_asyncwrite)) {
ProcessPendingAsyncWrites(); aeAcquireLock();
aeReleaseLock(); ProcessPendingAsyncWrites();
aeReleaseLock();
}
g_pserver->garbageCollector.endEpoch(serverTL->gcEpoch); g_pserver->garbageCollector.endEpoch(serverTL->gcEpoch);
serverTL->gcEpoch.reset(); serverTL->gcEpoch.reset();
} }
@ -61,6 +63,7 @@ bool AsyncWorkQueue::removeClientAsyncWrites(client *c)
{ {
bool fFound = false; bool fFound = false;
aeAcquireLock(); aeAcquireLock();
m_mutex.lock();
for (auto pvars : m_vecpthreadVars) for (auto pvars : m_vecpthreadVars)
{ {
listIter li; listIter li;
@ -75,6 +78,7 @@ bool AsyncWorkQueue::removeClientAsyncWrites(client *c)
} }
} }
} }
m_mutex.unlock();
aeReleaseLock(); aeReleaseLock();
return fFound; return fFound;
} }