Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
2435341d
Commit
2435341d
authored
May 14, 2020
by
Madelyn Olson
Committed by
antirez
May 15, 2020
Browse files
Added a refcount on timer events to prevent deletion of recursive timer calls
parent
80c906bd
Changes
2
Show whitespace changes
Inline
Side-by-side
src/ae.c
View file @
2435341d
...
@@ -238,6 +238,7 @@ long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
...
@@ -238,6 +238,7 @@ long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
te
->
clientData
=
clientData
;
te
->
clientData
=
clientData
;
te
->
prev
=
NULL
;
te
->
prev
=
NULL
;
te
->
next
=
eventLoop
->
timeEventHead
;
te
->
next
=
eventLoop
->
timeEventHead
;
te
->
refcount
=
0
;
if
(
te
->
next
)
if
(
te
->
next
)
te
->
next
->
prev
=
te
;
te
->
next
->
prev
=
te
;
eventLoop
->
timeEventHead
=
te
;
eventLoop
->
timeEventHead
=
te
;
...
@@ -316,6 +317,13 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
...
@@ -316,6 +317,13 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
/* Remove events scheduled for deletion. */
/* Remove events scheduled for deletion. */
if
(
te
->
id
==
AE_DELETED_EVENT_ID
)
{
if
(
te
->
id
==
AE_DELETED_EVENT_ID
)
{
aeTimeEvent
*
next
=
te
->
next
;
aeTimeEvent
*
next
=
te
->
next
;
/* If a reference exists for this timer event,
* don't free it. This is currently incremented
* for recursive timerProc calls */
if
(
te
->
refcount
)
{
te
=
next
;
continue
;
}
if
(
te
->
prev
)
if
(
te
->
prev
)
te
->
prev
->
next
=
te
->
next
;
te
->
prev
->
next
=
te
->
next
;
else
else
...
@@ -345,7 +353,9 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
...
@@ -345,7 +353,9 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
int
retval
;
int
retval
;
id
=
te
->
id
;
id
=
te
->
id
;
te
->
refcount
++
;
retval
=
te
->
timeProc
(
eventLoop
,
id
,
te
->
clientData
);
retval
=
te
->
timeProc
(
eventLoop
,
id
,
te
->
clientData
);
te
->
refcount
--
;
processed
++
;
processed
++
;
if
(
retval
!=
AE_NOMORE
)
{
if
(
retval
!=
AE_NOMORE
)
{
aeAddMillisecondsToNow
(
retval
,
&
te
->
when_sec
,
&
te
->
when_ms
);
aeAddMillisecondsToNow
(
retval
,
&
te
->
when_sec
,
&
te
->
when_ms
);
...
...
src/ae.h
View file @
2435341d
...
@@ -86,6 +86,8 @@ typedef struct aeTimeEvent {
...
@@ -86,6 +86,8 @@ typedef struct aeTimeEvent {
void
*
clientData
;
void
*
clientData
;
struct
aeTimeEvent
*
prev
;
struct
aeTimeEvent
*
prev
;
struct
aeTimeEvent
*
next
;
struct
aeTimeEvent
*
next
;
int
refcount
;
/* refcount to prevent timer events from being
* freed in recursive time event calls. */
}
aeTimeEvent
;
}
aeTimeEvent
;
/* A fired event */
/* A fired event */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment