Avoid locking if we won't run a time event
Former-commit-id: 33b05c859afd6665feae43c47d19f7a0a764c36b
This commit is contained in:
parent
85492ccee8
commit
9c65bd8f3d
@ -589,7 +589,7 @@ static aeTimeEvent *aeSearchNearestTimer(aeEventLoop *eventLoop)
|
|||||||
|
|
||||||
/* Process time events */
|
/* Process time events */
|
||||||
static int processTimeEvents(aeEventLoop *eventLoop) {
|
static int processTimeEvents(aeEventLoop *eventLoop) {
|
||||||
std::unique_lock<decltype(g_lock)> ulock(g_lock);
|
std::unique_lock<decltype(g_lock)> ulock(g_lock, std::defer_lock);
|
||||||
int processed = 0;
|
int processed = 0;
|
||||||
aeTimeEvent *te;
|
aeTimeEvent *te;
|
||||||
long long maxId;
|
long long maxId;
|
||||||
@ -634,8 +634,10 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
|
|||||||
eventLoop->timeEventHead = te->next;
|
eventLoop->timeEventHead = te->next;
|
||||||
if (te->next)
|
if (te->next)
|
||||||
te->next->prev = te->prev;
|
te->next->prev = te->prev;
|
||||||
if (te->finalizerProc)
|
if (te->finalizerProc) {
|
||||||
|
if (!ulock.owns_lock()) ulock.lock();
|
||||||
te->finalizerProc(eventLoop, te->clientData);
|
te->finalizerProc(eventLoop, te->clientData);
|
||||||
|
}
|
||||||
zfree(te);
|
zfree(te);
|
||||||
te = next;
|
te = next;
|
||||||
continue;
|
continue;
|
||||||
@ -654,6 +656,7 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
|
|||||||
if (now_sec > te->when_sec ||
|
if (now_sec > te->when_sec ||
|
||||||
(now_sec == te->when_sec && now_ms >= te->when_ms))
|
(now_sec == te->when_sec && now_ms >= te->when_ms))
|
||||||
{
|
{
|
||||||
|
if (!ulock.owns_lock()) ulock.lock();
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
id = te->id;
|
id = te->id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user