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
d374b0ef
Commit
d374b0ef
authored
Jul 21, 2016
by
Juho Snellman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up some memory management issues
- TimerEvent destructor should cancel timer. - Fix memory leak.
parent
4eb95a09
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
src/test/test_basic.cc
src/test/test_basic.cc
+7
-0
src/timer-wheel.h
src/timer-wheel.h
+7
-2
No files found.
src/test/test_basic.cc
View file @
d374b0ef
...
@@ -94,6 +94,13 @@ bool test_single_timer_no_hierarchy() {
...
@@ -94,6 +94,13 @@ bool test_single_timer_no_hierarchy() {
timers
.
advance
(
10
);
timers
.
advance
(
10
);
EXPECT_INTEQ
(
count
,
4
);
EXPECT_INTEQ
(
count
,
4
);
{
TimerEvent
<
Callback
>
timer2
([
&
count
]
()
{
++
count
;
});
timers
.
schedule
(
&
timer2
,
5
);
}
timers
.
advance
(
10
);
EXPECT_INTEQ
(
count
,
4
);
return
true
;
return
true
;
}
}
...
...
src/timer-wheel.h
View file @
d374b0ef
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include <cstdint>
#include <cstdint>
#include <cstdio>
#include <cstdio>
#include <limits>
#include <limits>
#include <memory>
typedef
uint64_t
Tick
;
typedef
uint64_t
Tick
;
...
@@ -22,6 +23,10 @@ public:
...
@@ -22,6 +23,10 @@ public:
TimerEventInterface
()
{
TimerEventInterface
()
{
}
}
virtual
~
TimerEventInterface
()
{
cancel
();
}
void
cancel
();
void
cancel
();
virtual
void
execute
()
=
0
;
virtual
void
execute
()
=
0
;
...
@@ -212,7 +217,7 @@ private:
...
@@ -212,7 +217,7 @@ private:
:
now_
(
0
),
:
now_
(
0
),
down_
(
down
)
{
down_
(
down
)
{
if
(
offset
+
WIDTH_BITS
<
64
)
{
if
(
offset
+
WIDTH_BITS
<
64
)
{
up_
=
new
TimerWheel
(
offset
+
WIDTH_BITS
,
down
);
up_
.
reset
(
new
TimerWheel
(
offset
+
WIDTH_BITS
,
down
)
);
}
}
}
}
...
@@ -222,7 +227,7 @@ private:
...
@@ -222,7 +227,7 @@ private:
static
const
int
NUM_SLOTS
=
1
<<
WIDTH_BITS
;
static
const
int
NUM_SLOTS
=
1
<<
WIDTH_BITS
;
static
const
int
MASK
=
(
NUM_SLOTS
-
1
);
static
const
int
MASK
=
(
NUM_SLOTS
-
1
);
TimerWheelSlot
slots_
[
NUM_SLOTS
];
TimerWheelSlot
slots_
[
NUM_SLOTS
];
TimerWheel
*
up_
;
std
::
unique_ptr
<
TimerWheel
>
up_
;
TimerWheel
*
down_
;
TimerWheel
*
down_
;
};
};
...
...
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