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
790e540c
Commit
790e540c
authored
Dec 01, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: use ClockCache
parent
16074c56
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
8 deletions
+20
-8
Loop.cxx
src/event/Loop.cxx
+6
-3
Loop.hxx
src/event/Loop.hxx
+14
-5
No files found.
src/event/Loop.cxx
View file @
790e540c
...
...
@@ -159,7 +159,7 @@ EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept
{
assert
(
IsInside
());
t
.
due
=
now
+
d
;
t
.
due
=
SteadyNow
()
+
d
;
timers
.
insert
(
t
);
again
=
true
;
}
...
...
@@ -167,6 +167,8 @@ EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept
inline
Event
::
Duration
EventLoop
::
HandleTimers
()
noexcept
{
const
auto
now
=
SteadyNow
();
Event
::
Duration
timeout
;
while
(
!
quit
)
{
...
...
@@ -301,8 +303,9 @@ EventLoop::Run() noexcept
};
#endif
steady_clock_cache
.
flush
();
do
{
now
=
std
::
chrono
::
steady_clock
::
now
();
again
=
false
;
/* invoke timers */
...
...
@@ -340,7 +343,7 @@ EventLoop::Run() noexcept
Wait
(
timeout
);
now
=
std
::
chrono
::
steady_clock
::
now
();
steady_clock_cache
.
flush
();
#ifdef HAVE_THREADED_EVENT_LOOP
{
...
...
src/event/Loop.hxx
View file @
790e540c
...
...
@@ -24,6 +24,7 @@
#include "Backend.hxx"
#include "SocketEvent.hxx"
#include "event/Features.h"
#include "time/ClockCache.hxx"
#include "util/Compiler.h"
#include "util/IntrusiveList.hxx"
...
...
@@ -114,8 +115,6 @@ class EventLoop final
std
::
unique_ptr
<
Uring
::
Manager
>
uring
;
#endif
Event
::
Clock
::
time_point
now
=
Event
::
Clock
::
now
();
#ifdef HAVE_THREADED_EVENT_LOOP
/**
* A reference to the thread that is currently inside Run().
...
...
@@ -155,6 +154,8 @@ class EventLoop final
EventPollBackend
poll_backend
;
ClockCache
<
std
::
chrono
::
steady_clock
>
steady_clock_cache
;
public
:
/**
* Throws on error.
...
...
@@ -172,15 +173,23 @@ public:
EventLoop
(
const
EventLoop
&
other
)
=
delete
;
EventLoop
&
operator
=
(
const
EventLoop
&
other
)
=
delete
;
const
auto
&
GetSteadyClockCache
()
const
noexcept
{
return
steady_clock_cache
;
}
/**
* A caching wrapper for Event::Clock::now().
* Caching wrapper for std::chrono::steady_clock::now(). The
* real clock is queried at most once per event loop
* iteration, because it is assumed that the event loop runs
* for a negligible duration.
*/
auto
GetTime
()
const
{
gcc_pure
const
auto
&
SteadyNow
()
const
noexcept
{
#ifdef HAVE_THREADED_EVENT_LOOP
assert
(
IsInside
());
#endif
return
now
;
return
steady_clock_cache
.
now
()
;
}
#ifdef HAVE_URING
...
...
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