need child specific release that doesn't trigger cv

This commit is contained in:
Malavan Sotheeswaran 2023-02-09 10:28:22 -08:00
parent 3492615c6a
commit b5ab1d64e2
4 changed files with 21 additions and 0 deletions

View File

@ -859,6 +859,11 @@ void aeReleaseForkLock()
g_forkLock.downgradeWrite();
}
void aeReleaseForkLockChild()
{
g_forkLock.downgradeWriteChild();
}
int aeThreadOwnsLock()
{
return fOwnLockOverride || g_lock.fOwnLock();

View File

@ -171,6 +171,7 @@ int aeTryAcquireLock(int fWeak);
void aeThreadOffline();
void aeReleaseLock();
void aeReleaseForkLock();
void aeReleaseForkLockChild();
int aeThreadOwnsLock();
void aeSetThreadOwnsLockOverride(int fOverride);
int aeLockContested(int threshold);

View File

@ -77,11 +77,25 @@ public:
m_cv.notify_all();
}
void releaseWriteChild(bool exclusive = true) {
std::unique_lock<fastlock> rm(m_readLock);
serverAssert(m_writeCount > 0);
if (exclusive)
m_writeLock.unlock();
m_writeCount--;
m_writeWaiting = false;
}
void downgradeWrite(bool exclusive = true) {
releaseWrite(exclusive);
acquireRead();
}
void downgradeWriteChild(bool exclusive = true) {
releaseWriteChild(exclusive);
acquireRead();
}
bool hasReader() {
return m_readCount > 0;
}

View File

@ -6888,6 +6888,7 @@ int redisFork(int purpose) {
latencyAddSampleIfNeeded("fork-lock",(ustime()-startWriteLock)/1000);
if ((childpid = fork()) == 0) {
/* Child */
aeReleaseForkLockChild();
g_pserver->in_fork_child = purpose;
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
setupChildSignalHandlers();