refactor aeReleaseForkLockChild to capture releaseRead case

This commit is contained in:
Malavan Sotheeswaran 2023-02-09 12:06:27 -08:00
parent b5ab1d64e2
commit 0cba0ed30b
4 changed files with 12 additions and 18 deletions

View File

@ -859,9 +859,9 @@ void aeReleaseForkLock()
g_forkLock.downgradeWrite();
}
void aeReleaseForkLockChild()
void aeForkLockInChild()
{
g_forkLock.downgradeWriteChild();
g_forkLock.setNotify(false);
}
int aeThreadOwnsLock()

View File

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

View File

@ -8,6 +8,7 @@ class readWriteLock {
int m_readCount = 0;
int m_writeCount = 0;
bool m_writeWaiting = false;
bool m_notify = true;
public:
readWriteLock(const char *name) : m_readLock(name), m_writeLock(name) {}
@ -65,7 +66,8 @@ public:
void releaseRead() {
std::unique_lock<fastlock> rm(m_readLock);
m_readCount--;
m_cv.notify_all();
if (m_notify)
m_cv.notify_all();
}
void releaseWrite(bool exclusive = true) {
@ -74,16 +76,8 @@ public:
if (exclusive)
m_writeLock.unlock();
m_writeCount--;
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;
if (m_notify)
m_cv.notify_all();
}
void downgradeWrite(bool exclusive = true) {
@ -91,9 +85,8 @@ public:
acquireRead();
}
void downgradeWriteChild(bool exclusive = true) {
releaseWriteChild(exclusive);
acquireRead();
void setNotify(bool notify) {
m_notify = notify;
}
bool hasReader() {

View File

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