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
1b4fd745
Commit
1b4fd745
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/TimerEvent: rename to FineTimerEvent
... and make TimerEvent a type alias for FineTimerEvent (i.e. swap names).
parent
def962b6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
130 additions
and
113 deletions
+130
-113
FineTimerEvent.cxx
src/event/FineTimerEvent.cxx
+29
-16
FineTimerEvent.hxx
src/event/FineTimerEvent.hxx
+55
-3
Loop.cxx
src/event/Loop.cxx
+1
-2
Loop.hxx
src/event/Loop.hxx
+1
-1
TimerEvent.hxx
src/event/TimerEvent.hxx
+31
-78
TimerList.cxx
src/event/TimerList.cxx
+5
-5
TimerList.hxx
src/event/TimerList.hxx
+7
-7
meson.build
src/event/meson.build
+1
-1
No files found.
src/event/TimerEvent.cxx
→
src/event/
Fine
TimerEvent.cxx
View file @
1b4fd745
/*
* Copyright 200
3-2021 The Music Player Daemon Project
*
http://www.musicpd.org
* Copyright 200
7-2021 CM4all GmbH
*
All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* author: Max Kellermann <mk@cm4all.com>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* - 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 "TimerEvent.hxx"
#include "
Fine
TimerEvent.hxx"
#include "Loop.hxx"
void
TimerEvent
::
Schedule
(
Event
::
Duration
d
)
noexcept
Fine
TimerEvent
::
Schedule
(
Event
::
Duration
d
)
noexcept
{
Cancel
();
...
...
@@ -30,7 +43,7 @@ TimerEvent::Schedule(Event::Duration d) noexcept
}
void
TimerEvent
::
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
Fine
TimerEvent
::
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
{
const
auto
new_due
=
loop
.
SteadyNow
()
+
d
;
...
...
src/event/FineTimerEvent.hxx
View file @
1b4fd745
...
...
@@ -32,7 +32,12 @@
#pragma once
#include "TimerEvent.hxx"
#include "Chrono.hxx"
#include "util/BindMethod.hxx"
#include <boost/intrusive/set_hook.hpp>
class
EventLoop
;
/**
* This class invokes a callback function after a certain amount of
...
...
@@ -45,5 +50,52 @@
* thread that runs the #EventLoop, except where explicitly documented
* as thread-safe.
*/
using
FineTimerEvent
=
TimerEvent
;
// TODO: implement
class
FineTimerEvent
final
:
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
{
friend
class
TimerList
;
EventLoop
&
loop
;
using
Callback
=
BoundMethod
<
void
()
noexcept
>
;
const
Callback
callback
;
/**
* When is this timer due? This is only valid if IsPending()
* returns true.
*/
Event
::
Clock
::
time_point
due
;
public
:
FineTimerEvent
(
EventLoop
&
_loop
,
Callback
_callback
)
noexcept
:
loop
(
_loop
),
callback
(
_callback
)
{}
auto
&
GetEventLoop
()
const
noexcept
{
return
loop
;
}
constexpr
auto
GetDue
()
const
noexcept
{
return
due
;
}
bool
IsPending
()
const
noexcept
{
return
is_linked
();
}
void
Schedule
(
Event
::
Duration
d
)
noexcept
;
/**
* Like Schedule(), but is a no-op if there is a due time
* earlier than the given one.
*/
void
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
;
void
Cancel
()
noexcept
{
unlink
();
}
private
:
void
Run
()
noexcept
{
callback
();
}
};
src/event/Loop.cxx
View file @
1b4fd745
...
...
@@ -18,7 +18,6 @@
*/
#include "Loop.hxx"
#include "TimerEvent.hxx"
#include "DeferEvent.hxx"
#include "SocketEvent.hxx"
#include "IdleEvent.hxx"
...
...
@@ -144,7 +143,7 @@ EventLoop::AbandonFD(SocketEvent &event) noexcept
}
void
EventLoop
::
Insert
(
TimerEvent
&
t
)
noexcept
EventLoop
::
Insert
(
Fine
TimerEvent
&
t
)
noexcept
{
assert
(
IsInside
());
...
...
src/event/Loop.hxx
View file @
1b4fd745
...
...
@@ -204,7 +204,7 @@ public:
*/
bool
AbandonFD
(
SocketEvent
&
event
)
noexcept
;
void
Insert
(
TimerEvent
&
t
)
noexcept
;
void
Insert
(
Fine
TimerEvent
&
t
)
noexcept
;
/**
* Schedule a call to DeferEvent::RunDeferred().
...
...
src/event/TimerEvent.hxx
View file @
1b4fd745
/*
* Copyright 200
3-2021 The Music Player Daemon Project
*
http://www.musicpd.org
* Copyright 200
7-2021 CM4all GmbH
*
All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* author: Max Kellermann <mk@cm4all.com>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* - 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.
*/
#ifndef MPD_TIMER_EVENT_HXX
#define MPD_TIMER_EVENT_HXX
#include "Chrono.hxx"
#include "util/BindMethod.hxx"
#pragma once
#include <boost/intrusive/set_hook.hpp>
class
EventLoop
;
#include "FineTimerEvent.hxx"
/**
* This class invokes a callback function after a certain amount of
* time. Use Schedule() to start the timer or Cancel() to cancel it.
*
* This class is not thread-safe, all methods must be called from the
* thread that runs the #EventLoop, except where explicitly documented
* as thread-safe.
* This is a transitional alias. Use #FineTimerEvent or
* #CoarseTimerEvent instead.
*/
class
TimerEvent
final
:
public
boost
::
intrusive
::
set_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
{
friend
class
TimerList
;
EventLoop
&
loop
;
using
Callback
=
BoundMethod
<
void
()
noexcept
>
;
const
Callback
callback
;
/**
* When is this timer due? This is only valid if IsPending()
* returns true.
*/
Event
::
Clock
::
time_point
due
;
public
:
TimerEvent
(
EventLoop
&
_loop
,
Callback
_callback
)
noexcept
:
loop
(
_loop
),
callback
(
_callback
)
{}
auto
&
GetEventLoop
()
const
noexcept
{
return
loop
;
}
constexpr
auto
GetDue
()
const
noexcept
{
return
due
;
}
bool
IsPending
()
const
noexcept
{
return
is_linked
();
}
void
Schedule
(
Event
::
Duration
d
)
noexcept
;
/**
* Like Schedule(), but is a no-op if there is a due time
* earlier than the given one.
*/
void
ScheduleEarlier
(
Event
::
Duration
d
)
noexcept
;
void
Cancel
()
noexcept
{
unlink
();
}
private
:
void
Run
()
noexcept
{
callback
();
}
};
#endif
/* MAIN_NOTIFY_H */
using
TimerEvent
=
FineTimerEvent
;
src/event/TimerList.cxx
View file @
1b4fd745
...
...
@@ -31,11 +31,11 @@
*/
#include "Loop.hxx"
#include "TimerEvent.hxx"
#include "
Fine
TimerEvent.hxx"
constexpr
bool
TimerList
::
Compare
::
operator
()(
const
TimerEvent
&
a
,
const
TimerEvent
&
b
)
const
noexcept
TimerList
::
Compare
::
operator
()(
const
Fine
TimerEvent
&
a
,
const
Fine
TimerEvent
&
b
)
const
noexcept
{
return
a
.
due
<
b
.
due
;
}
...
...
@@ -48,7 +48,7 @@ TimerList::~TimerList() noexcept
}
void
TimerList
::
Insert
(
TimerEvent
&
t
)
noexcept
TimerList
::
Insert
(
Fine
TimerEvent
&
t
)
noexcept
{
timers
.
insert
(
t
);
}
...
...
@@ -61,7 +61,7 @@ TimerList::Run(const Event::Clock::time_point now) noexcept
if
(
i
==
timers
.
end
())
break
;
TimerEvent
&
t
=
*
i
;
auto
&
t
=
*
i
;
const
auto
timeout
=
t
.
due
-
now
;
if
(
timeout
>
timeout
.
zero
())
return
timeout
;
...
...
src/event/TimerList.hxx
View file @
1b4fd745
...
...
@@ -37,18 +37,18 @@
#include <boost/intrusive/set.hpp>
class
TimerEvent
;
class
Fine
TimerEvent
;
/**
* A list of #TimerEvent instances sorted by due time point.
* A list of #
Fine
TimerEvent instances sorted by due time point.
*/
class
TimerList
final
{
struct
Compare
{
constexpr
bool
operator
()(
const
TimerEvent
&
a
,
const
TimerEvent
&
b
)
const
noexcept
;
constexpr
bool
operator
()(
const
Fine
TimerEvent
&
a
,
const
Fine
TimerEvent
&
b
)
const
noexcept
;
};
boost
::
intrusive
::
multiset
<
TimerEvent
,
boost
::
intrusive
::
multiset
<
Fine
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
;
...
...
@@ -64,10 +64,10 @@ public:
return
timers
.
empty
();
}
void
Insert
(
TimerEvent
&
t
)
noexcept
;
void
Insert
(
Fine
TimerEvent
&
t
)
noexcept
;
/**
* Invoke all expired #TimerEvent instances and return the
* Invoke all expired #
Fine
TimerEvent instances and return the
* duration until the next timer expires. Returns a negative
* duration if there is no timeout.
*/
...
...
src/event/meson.build
View file @
1b4fd745
...
...
@@ -23,7 +23,7 @@ event = static_library(
'event',
'SignalMonitor.cxx',
'TimerList.cxx',
'TimerEvent.cxx',
'
Fine
TimerEvent.cxx',
'IdleEvent.cxx',
'InjectEvent.cxx',
'DeferEvent.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