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
e802f1f6
Commit
e802f1f6
authored
Feb 04, 2021
by
Max Kellermann
Committed by
Max Kellermann
Feb 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: move TimerSet to separate class
parent
271b2873
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
160 additions
and
42 deletions
+160
-42
Loop.cxx
src/event/Loop.cxx
+2
-29
Loop.hxx
src/event/Loop.hxx
+2
-12
TimerEvent.hxx
src/event/TimerEvent.hxx
+5
-1
TimerList.cxx
src/event/TimerList.cxx
+75
-0
TimerList.hxx
src/event/TimerList.hxx
+75
-0
meson.build
src/event/meson.build
+1
-0
No files found.
src/event/Loop.cxx
View file @
e802f1f6
...
...
@@ -34,13 +34,6 @@
#include <stdio.h>
#endif
constexpr
bool
EventLoop
::
TimerCompare
::
operator
()(
const
TimerEvent
&
a
,
const
TimerEvent
&
b
)
const
noexcept
{
return
a
.
due
<
b
.
due
;
}
EventLoop
::
EventLoop
(
#ifdef HAVE_THREADED_EVENT_LOOP
ThreadId
_thread
...
...
@@ -60,7 +53,6 @@ EventLoop::EventLoop(
EventLoop
::~
EventLoop
()
noexcept
{
assert
(
timers
.
empty
());
assert
(
defer
.
empty
());
assert
(
idle
.
empty
());
#ifdef HAVE_THREADED_EVENT_LOOP
...
...
@@ -156,33 +148,14 @@ EventLoop::Insert(TimerEvent &t) noexcept
{
assert
(
IsInside
());
timers
.
i
nsert
(
t
);
timers
.
I
nsert
(
t
);
again
=
true
;
}
inline
Event
::
Duration
EventLoop
::
HandleTimers
()
noexcept
{
const
auto
now
=
SteadyNow
();
Event
::
Duration
timeout
;
while
(
!
quit
)
{
auto
i
=
timers
.
begin
();
if
(
i
==
timers
.
end
())
break
;
TimerEvent
&
t
=
*
i
;
timeout
=
t
.
due
-
now
;
if
(
timeout
>
timeout
.
zero
())
return
timeout
;
timers
.
erase
(
i
);
t
.
Run
();
}
return
Event
::
Duration
(
-
1
);
return
timers
.
Run
(
SteadyNow
());
}
void
...
...
src/event/Loop.hxx
View file @
e802f1f6
...
...
@@ -21,6 +21,7 @@
#define EVENT_LOOP_HXX
#include "Chrono.hxx"
#include "TimerList.hxx"
#include "Backend.hxx"
#include "SocketEvent.hxx"
#include "event/Features.h"
...
...
@@ -45,7 +46,6 @@
namespace
Uring
{
class
Queue
;
class
Manager
;
}
#endif
class
TimerEvent
;
class
DeferEvent
;
class
InjectEvent
;
...
...
@@ -65,17 +65,7 @@ class EventLoop final
SocketEvent
wake_event
{
*
this
,
BIND_THIS_METHOD
(
OnSocketReady
),
wake_fd
.
GetSocket
()};
#endif
struct
TimerCompare
{
constexpr
bool
operator
()(
const
TimerEvent
&
a
,
const
TimerEvent
&
b
)
const
noexcept
;
};
using
TimerSet
=
boost
::
intrusive
::
multiset
<
TimerEvent
,
boost
::
intrusive
::
base_hook
<
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>>
,
boost
::
intrusive
::
compare
<
TimerCompare
>
,
boost
::
intrusive
::
constant_time_size
<
false
>>
;
TimerSet
timers
;
TimerList
timers
;
using
DeferList
=
IntrusiveList
<
DeferEvent
>
;
...
...
src/event/TimerEvent.hxx
View file @
e802f1f6
...
...
@@ -38,7 +38,7 @@ class EventLoop;
class
TimerEvent
final
:
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
{
friend
class
EventLoop
;
friend
class
TimerList
;
EventLoop
&
loop
;
...
...
@@ -59,6 +59,10 @@ public:
return
loop
;
}
constexpr
auto
GetDue
()
const
noexcept
{
return
due
;
}
bool
IsPending
()
const
noexcept
{
return
is_linked
();
}
...
...
src/event/TimerList.cxx
0 → 100644
View file @
e802f1f6
/*
* Copyright 2007-2021 CM4all GmbH
* All rights reserved.
*
* author: Max Kellermann <mk@cm4all.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Loop.hxx"
#include "TimerEvent.hxx"
constexpr
bool
TimerList
::
Compare
::
operator
()(
const
TimerEvent
&
a
,
const
TimerEvent
&
b
)
const
noexcept
{
return
a
.
due
<
b
.
due
;
}
TimerList
::
TimerList
()
=
default
;
TimerList
::~
TimerList
()
noexcept
{
assert
(
timers
.
empty
());
}
void
TimerList
::
Insert
(
TimerEvent
&
t
)
noexcept
{
timers
.
insert
(
t
);
}
Event
::
Duration
TimerList
::
Run
(
const
Event
::
Clock
::
time_point
now
)
noexcept
{
while
(
true
)
{
auto
i
=
timers
.
begin
();
if
(
i
==
timers
.
end
())
break
;
TimerEvent
&
t
=
*
i
;
const
auto
timeout
=
t
.
due
-
now
;
if
(
timeout
>
timeout
.
zero
())
return
timeout
;
timers
.
erase
(
i
);
t
.
Run
();
}
return
Event
::
Duration
(
-
1
);
}
src/event/TimerList.hxx
0 → 100644
View file @
e802f1f6
/*
* Copyright 2007-2021 CM4all GmbH
* All rights reserved.
*
* author: Max Kellermann <mk@cm4all.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "Chrono.hxx"
#include "util/IntrusiveList.hxx"
#include <boost/intrusive/set.hpp>
class
TimerEvent
;
/**
* A list of #TimerEvent instances sorted by due time point.
*/
class
TimerList
final
{
struct
Compare
{
constexpr
bool
operator
()(
const
TimerEvent
&
a
,
const
TimerEvent
&
b
)
const
noexcept
;
};
boost
::
intrusive
::
multiset
<
TimerEvent
,
boost
::
intrusive
::
base_hook
<
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>>
,
boost
::
intrusive
::
compare
<
Compare
>
,
boost
::
intrusive
::
constant_time_size
<
false
>>
timers
;
public
:
TimerList
();
~
TimerList
()
noexcept
;
TimerList
(
const
TimerList
&
other
)
=
delete
;
TimerList
&
operator
=
(
const
TimerList
&
other
)
=
delete
;
bool
IsEmpty
()
const
noexcept
{
return
timers
.
empty
();
}
void
Insert
(
TimerEvent
&
t
)
noexcept
;
/**
* Invoke all expired #TimerEvent instances and return the
* duration until the next timer expires. Returns a negative
* duration if there is no timeout.
*/
Event
::
Duration
Run
(
Event
::
Clock
::
time_point
now
)
noexcept
;
};
src/event/meson.build
View file @
e802f1f6
...
...
@@ -22,6 +22,7 @@ endif
event = static_library(
'event',
'SignalMonitor.cxx',
'TimerList.cxx',
'TimerEvent.cxx',
'IdleEvent.cxx',
'InjectEvent.cxx',
...
...
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