Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
Ratas
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Ratas
Commits
816901d6
Commit
816901d6
authored
Jul 20, 2016
by
Juho Snellman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug with timer rescheduling
- Not enough to just redefine the relink() method, need to also use it...
parent
ac748567
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
src/test/test_basic.cc
src/test/test_basic.cc
+18
-3
src/timer-wheel.h
src/timer-wheel.h
+11
-1
No files found.
src/test/test_basic.cc
View file @
816901d6
...
...
@@ -43,22 +43,28 @@ bool test_single_timer_no_hierarchy() {
int
count
=
0
;
TimerEvent
<
Callback
>
timer
([
&
count
]
()
{
++
count
;
});
// Unscheduled timer does nothing.
timers
.
advance
(
10
);
EXPECT_INTEQ
(
count
,
0
);
EXPECT
(
!
timer
.
active
());
// Schedule timer, should trigger at right time.
timers
.
schedule
(
&
timer
,
5
);
EXPECT
(
timer
.
active
());
timers
.
advance
(
10
);
timers
.
advance
(
5
);
EXPECT_INTEQ
(
count
,
1
);
timers
.
advance
(
10
);
// Only trigger once, not repeatedly (even if wheel wraps
// around).
timers
.
advance
(
256
);
EXPECT_INTEQ
(
count
,
1
);
// ... unless, of course, the timer gets scheduled again.
timers
.
schedule
(
&
timer
,
5
);
timers
.
advance
(
10
);
timers
.
advance
(
5
);
EXPECT_INTEQ
(
count
,
2
);
// Canceled timers don't run.
timers
.
schedule
(
&
timer
,
5
);
timer
.
cancel
();
EXPECT
(
!
timer
.
active
());
...
...
@@ -71,6 +77,15 @@ bool test_single_timer_no_hierarchy() {
timers
.
advance
(
10
);
EXPECT_INTEQ
(
count
,
3
);
// Timers that are scheduled multiple times only run at the last
// scheduled tick.
timers
.
schedule
(
&
timer
,
5
);
timers
.
schedule
(
&
timer
,
10
);
timers
.
advance
(
5
);
EXPECT_INTEQ
(
count
,
3
);
timers
.
advance
(
5
);
EXPECT_INTEQ
(
count
,
4
);
return
true
;
}
...
...
src/timer-wheel.h
View file @
816901d6
...
...
@@ -153,8 +153,18 @@ public:
size_t
slot_index
=
(
now_
+
delta
)
&
MASK
;
auto
slot
=
&
slots_
[
slot_index
];
if
(
event
->
active
())
{
event
->
relink
(
slot
);
}
else
{
slot
->
push_event
(
event
);
}
}
// Return the current tick value. Note that if the timers advance by
// multiple ticks during a single call to advance(), the value of now()
// will be the tick on which the timer was first run. Not the tick that
// the timer eventually will advance to.
const
Tick
&
now
()
const
{
return
now_
;
}
private:
TimerWheel
(
const
TimerWheel
&
other
)
=
delete
;
...
...
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