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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
3 deletions
+44
-3
FineTimerEvent.hxx
src/event/FineTimerEvent.hxx
+18
-3
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 @@
...
@@ -33,9 +33,14 @@
#pragma once
#pragma once
#include "Chrono.hxx"
#include "Chrono.hxx"
#include "event/Features.h"
#include "util/BindMethod.hxx"
#include "util/BindMethod.hxx"
#ifdef NO_BOOST
#include "util/IntrusiveList.hxx"
#else
#include <boost/intrusive/set_hook.hpp>
#include <boost/intrusive/set_hook.hpp>
#endif
class
EventLoop
;
class
EventLoop
;
...
@@ -50,10 +55,17 @@ class EventLoop;
...
@@ -50,10 +55,17 @@ class EventLoop;
* thread that runs the #EventLoop, except where explicitly documented
* thread that runs the #EventLoop, except where explicitly documented
* as thread-safe.
* as thread-safe.
*/
*/
class
FineTimerEvent
final
class
FineTimerEvent
final
:
:
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
#ifdef NO_BOOST
AutoUnlinkIntrusiveListHook
#else
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
#endif
{
{
friend
class
TimerList
;
friend
class
TimerList
;
#ifdef NO_BOOST
friend
class
IntrusiveList
<
FineTimerEvent
>
;
#endif
EventLoop
&
loop
;
EventLoop
&
loop
;
...
@@ -91,7 +103,10 @@ public:
...
@@ -91,7 +103,10 @@ public:
void
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
;
void
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
;
void
Cancel
()
noexcept
{
void
Cancel
()
noexcept
{
unlink
();
#ifdef NO_BOOST
if
(
IsPending
())
#endif
unlink
();
}
}
private
:
private
:
...
...
src/event/TimerList.cxx
View file @
1ac16516
...
@@ -33,6 +33,10 @@
...
@@ -33,6 +33,10 @@
#include "Loop.hxx"
#include "Loop.hxx"
#include "FineTimerEvent.hxx"
#include "FineTimerEvent.hxx"
#ifdef NO_BOOST
#include <algorithm>
#endif
constexpr
bool
constexpr
bool
TimerList
::
Compare
::
operator
()(
const
FineTimerEvent
&
a
,
TimerList
::
Compare
::
operator
()(
const
FineTimerEvent
&
a
,
const
FineTimerEvent
&
b
)
const
noexcept
const
FineTimerEvent
&
b
)
const
noexcept
...
@@ -50,7 +54,15 @@ TimerList::~TimerList() noexcept
...
@@ -50,7 +54,15 @@ TimerList::~TimerList() noexcept
void
void
TimerList
::
Insert
(
FineTimerEvent
&
t
)
noexcept
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
);
timers
.
insert
(
t
);
#endif
}
}
Event
::
Duration
Event
::
Duration
...
@@ -66,7 +78,11 @@ TimerList::Run(const Event::TimePoint now) noexcept
...
@@ -66,7 +78,11 @@ TimerList::Run(const Event::TimePoint now) noexcept
if
(
timeout
>
timeout
.
zero
())
if
(
timeout
>
timeout
.
zero
())
return
timeout
;
return
timeout
;
#ifdef NO_BOOST
t
.
Cancel
();
#else
timers
.
erase
(
i
);
timers
.
erase
(
i
);
#endif
t
.
Run
();
t
.
Run
();
}
}
...
...
src/event/TimerList.hxx
View file @
1ac16516
...
@@ -33,9 +33,12 @@
...
@@ -33,9 +33,12 @@
#pragma once
#pragma once
#include "Chrono.hxx"
#include "Chrono.hxx"
#include "event/Features.h"
#include "util/IntrusiveList.hxx"
#include "util/IntrusiveList.hxx"
#ifndef NO_BOOST
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/set.hpp>
#endif
class
FineTimerEvent
;
class
FineTimerEvent
;
...
@@ -48,10 +51,17 @@ class TimerList final {
...
@@ -48,10 +51,17 @@ class TimerList final {
const
FineTimerEvent
&
b
)
const
noexcept
;
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
::
multiset
<
FineTimerEvent
,
boost
::
intrusive
::
base_hook
<
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>>
,
boost
::
intrusive
::
base_hook
<
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>>
,
boost
::
intrusive
::
compare
<
Compare
>
,
boost
::
intrusive
::
compare
<
Compare
>
,
boost
::
intrusive
::
constant_time_size
<
false
>>
timers
;
boost
::
intrusive
::
constant_time_size
<
false
>>
timers
;
#endif
public
:
public
:
TimerList
();
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