Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
7d502fb4
Commit
7d502fb4
authored
Mar 05, 2019
by
Max Kellermann
Committed by
Max Kellermann
Oct 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: round epoll_wait() timeout up
This implements proper rounding, amending commit
dcbb9fe0
parent
3ac87bbc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
Loop.cxx
src/event/Loop.cxx
+13
-2
No files found.
src/event/Loop.cxx
View file @
7d502fb4
...
...
@@ -162,6 +162,18 @@ EventLoop::HandleTimers() noexcept
return
Event
::
Duration
(
-
1
);
}
template
<
class
ToDuration
,
class
Rep
,
class
Period
>
static
constexpr
ToDuration
duration_cast_round_up
(
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
noexcept
{
using
FromDuration
=
decltype
(
d
);
constexpr
auto
one
=
std
::
chrono
::
duration_cast
<
FromDuration
>
(
ToDuration
(
1
));
constexpr
auto
round_add
=
one
>
one
.
zero
()
?
one
-
FromDuration
(
1
)
:
one
.
zero
();
return
std
::
chrono
::
duration_cast
<
ToDuration
>
(
d
+
round_add
);
}
/**
* Convert the given timeout specification to a milliseconds integer,
* to be used by functions like poll() and epoll_wait(). Any negative
...
...
@@ -171,8 +183,7 @@ static constexpr int
ExportTimeoutMS
(
Event
::
Duration
timeout
)
{
return
timeout
>=
timeout
.
zero
()
/* round up (+1) to avoid unnecessary wakeups */
?
int
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
timeout
).
count
())
+
1
?
int
(
duration_cast_round_up
<
std
::
chrono
::
milliseconds
>
(
timeout
).
count
())
:
-
1
;
}
...
...
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