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
1ac16516
Commit
1ac16516
authored
Feb 17, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/TimerList: add option to avoid the Boost dependency
parent
75e8795e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
FineTimerEvent.hxx
src/event/FineTimerEvent.hxx
+17
-2
TimerList.cxx
src/event/TimerList.cxx
+16
-0
TimerList.hxx
src/event/TimerList.hxx
+10
-0
No files found.
src/event/FineTimerEvent.hxx
View file @
1ac16516
...
...
@@ -33,9 +33,14 @@
#pragma once
#include "Chrono.hxx"
#include "event/Features.h"
#include "util/BindMethod.hxx"
#ifdef NO_BOOST
#include "util/IntrusiveList.hxx"
#else
#include <boost/intrusive/set_hook.hpp>
#endif
class
EventLoop
;
...
...
@@ -50,10 +55,17 @@ class EventLoop;
* thread that runs the #EventLoop, except where explicitly documented
* as thread-safe.
*/
class
FineTimerEvent
final
:
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
class
FineTimerEvent
final
:
#ifdef NO_BOOST
AutoUnlinkIntrusiveListHook
#else
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
#endif
{
friend
class
TimerList
;
#ifdef NO_BOOST
friend
class
IntrusiveList
<
FineTimerEvent
>
;
#endif
EventLoop
&
loop
;
...
...
@@ -91,6 +103,9 @@ public:
void
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
;
void
Cancel
()
noexcept
{
#ifdef NO_BOOST
if
(
IsPending
())
#endif
unlink
();
}
...
...
src/event/TimerList.cxx
View file @
1ac16516
...
...
@@ -33,6 +33,10 @@
#include "Loop.hxx"
#include "FineTimerEvent.hxx"
#ifdef NO_BOOST
#include <algorithm>
#endif
constexpr
bool
TimerList
::
Compare
::
operator
()(
const
FineTimerEvent
&
a
,
const
FineTimerEvent
&
b
)
const
noexcept
...
...
@@ -50,7 +54,15 @@ TimerList::~TimerList() noexcept
void
TimerList
::
Insert
(
FineTimerEvent
&
t
)
noexcept
{
#ifdef NO_BOOST
auto
i
=
std
::
find_if
(
timers
.
begin
(),
timers
.
end
(),
[
due
=
t
.
GetDue
()](
const
auto
&
other
){
return
other
.
GetDue
()
>=
due
;
});
timers
.
insert
(
i
,
t
);
#else
timers
.
insert
(
t
);
#endif
}
Event
::
Duration
...
...
@@ -66,7 +78,11 @@ TimerList::Run(const Event::TimePoint now) noexcept
if
(
timeout
>
timeout
.
zero
())
return
timeout
;
#ifdef NO_BOOST
t
.
Cancel
();
#else
timers
.
erase
(
i
);
#endif
t
.
Run
();
}
...
...
src/event/TimerList.hxx
View file @
1ac16516
...
...
@@ -33,9 +33,12 @@
#pragma once
#include "Chrono.hxx"
#include "event/Features.h"
#include "util/IntrusiveList.hxx"
#ifndef NO_BOOST
#include <boost/intrusive/set.hpp>
#endif
class
FineTimerEvent
;
...
...
@@ -48,10 +51,17 @@ class TimerList final {
const
FineTimerEvent
&
b
)
const
noexcept
;
};
#ifdef NO_BOOST
/* when building without Boost, then this is just a sorted
doubly-linked list - this doesn't scale well, but is good
enough for most programs */
IntrusiveList
<
FineTimerEvent
>
timers
;
#else
boost
::
intrusive
::
multiset
<
FineTimerEvent
,
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
;
#endif
public
:
TimerList
();
...
...
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