refactor aeReleaseForkLockChild to capture releaseRead case
This commit is contained in:
parent
b5ab1d64e2
commit
0cba0ed30b
@ -859,9 +859,9 @@ void aeReleaseForkLock()
|
|||||||
g_forkLock.downgradeWrite();
|
g_forkLock.downgradeWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
void aeReleaseForkLockChild()
|
void aeForkLockInChild()
|
||||||
{
|
{
|
||||||
g_forkLock.downgradeWriteChild();
|
g_forkLock.setNotify(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int aeThreadOwnsLock()
|
int aeThreadOwnsLock()
|
||||||
|
2
src/ae.h
2
src/ae.h
@ -171,7 +171,7 @@ int aeTryAcquireLock(int fWeak);
|
|||||||
void aeThreadOffline();
|
void aeThreadOffline();
|
||||||
void aeReleaseLock();
|
void aeReleaseLock();
|
||||||
void aeReleaseForkLock();
|
void aeReleaseForkLock();
|
||||||
void aeReleaseForkLockChild();
|
void aeForkLockInChild();
|
||||||
int aeThreadOwnsLock();
|
int aeThreadOwnsLock();
|
||||||
void aeSetThreadOwnsLockOverride(int fOverride);
|
void aeSetThreadOwnsLockOverride(int fOverride);
|
||||||
int aeLockContested(int threshold);
|
int aeLockContested(int threshold);
|
||||||
|
@ -8,6 +8,7 @@ class readWriteLock {
|
|||||||
int m_readCount = 0;
|
int m_readCount = 0;
|
||||||
int m_writeCount = 0;
|
int m_writeCount = 0;
|
||||||
bool m_writeWaiting = false;
|
bool m_writeWaiting = false;
|
||||||
|
bool m_notify = true;
|
||||||
public:
|
public:
|
||||||
readWriteLock(const char *name) : m_readLock(name), m_writeLock(name) {}
|
readWriteLock(const char *name) : m_readLock(name), m_writeLock(name) {}
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ public:
|
|||||||
void releaseRead() {
|
void releaseRead() {
|
||||||
std::unique_lock<fastlock> rm(m_readLock);
|
std::unique_lock<fastlock> rm(m_readLock);
|
||||||
m_readCount--;
|
m_readCount--;
|
||||||
|
if (m_notify)
|
||||||
m_cv.notify_all();
|
m_cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,26 +76,17 @@ public:
|
|||||||
if (exclusive)
|
if (exclusive)
|
||||||
m_writeLock.unlock();
|
m_writeLock.unlock();
|
||||||
m_writeCount--;
|
m_writeCount--;
|
||||||
|
if (m_notify)
|
||||||
m_cv.notify_all();
|
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) {
|
void downgradeWrite(bool exclusive = true) {
|
||||||
releaseWrite(exclusive);
|
releaseWrite(exclusive);
|
||||||
acquireRead();
|
acquireRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void downgradeWriteChild(bool exclusive = true) {
|
void setNotify(bool notify) {
|
||||||
releaseWriteChild(exclusive);
|
m_notify = notify;
|
||||||
acquireRead();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasReader() {
|
bool hasReader() {
|
||||||
|
@ -6888,7 +6888,8 @@ int redisFork(int purpose) {
|
|||||||
latencyAddSampleIfNeeded("fork-lock",(ustime()-startWriteLock)/1000);
|
latencyAddSampleIfNeeded("fork-lock",(ustime()-startWriteLock)/1000);
|
||||||
if ((childpid = fork()) == 0) {
|
if ((childpid = fork()) == 0) {
|
||||||
/* Child */
|
/* Child */
|
||||||
aeReleaseForkLockChild();
|
aeForkLockInChild();
|
||||||
|
aeReleaseForkLock();
|
||||||
g_pserver->in_fork_child = purpose;
|
g_pserver->in_fork_child = purpose;
|
||||||
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
|
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
|
||||||
setupChildSignalHandlers();
|
setupChildSignalHandlers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user