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
b57e2f55
Commit
b57e2f55
authored
Nov 12, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/DeferredMonitor: eliminate obsolete class
Move its code to DeferEvent instead.
parent
bf3ced6a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
95 deletions
+49
-95
Makefile.am
Makefile.am
+1
-2
DeferEvent.cxx
src/event/DeferEvent.cxx
+3
-3
DeferEvent.hxx
src/event/DeferEvent.hxx
+29
-8
DeferredMonitor.hxx
src/event/DeferredMonitor.hxx
+0
-66
Loop.cxx
src/event/Loop.cxx
+6
-6
Loop.hxx
src/event/Loop.hxx
+10
-10
No files found.
Makefile.am
View file @
b57e2f55
...
...
@@ -523,8 +523,7 @@ libevent_a_SOURCES = \
src/event/SignalMonitor.hxx src/event/SignalMonitor.cxx
\
src/event/TimerEvent.hxx src/event/TimerEvent.cxx
\
src/event/IdleMonitor.hxx src/event/IdleMonitor.cxx
\
src/event/DeferredMonitor.hxx src/event/DeferredMonitor.cxx
\
src/event/DeferEvent.hxx
\
src/event/DeferEvent.cxx src/event/DeferEvent.hxx
\
src/event/MaskMonitor.hxx src/event/MaskMonitor.cxx
\
src/event/SocketMonitor.cxx src/event/SocketMonitor.hxx
\
src/event/BufferedSocket.cxx src/event/BufferedSocket.hxx
\
...
...
src/event/Defer
redMonitor
.cxx
→
src/event/Defer
Event
.cxx
View file @
b57e2f55
...
...
@@ -18,17 +18,17 @@
*/
#include "config.h"
#include "Defer
redMonitor
.hxx"
#include "Defer
Event
.hxx"
#include "Loop.hxx"
void
Defer
redMonitor
::
Cancel
()
Defer
Event
::
Cancel
()
noexcept
{
loop
.
RemoveDeferred
(
*
this
);
}
void
Defer
redMonitor
::
Schedule
()
Defer
Event
::
Schedule
()
noexcept
{
loop
.
AddDeferred
(
*
this
);
}
src/event/DeferEvent.hxx
View file @
b57e2f55
...
...
@@ -21,28 +21,49 @@
#define MPD_DEFER_EVENT_HXX
#include "check.h"
#include "DeferredMonitor.hxx"
#include "util/BindMethod.hxx"
#include <boost/intrusive/list_hook.hpp>
class
EventLoop
;
/**
* Invoke a method call in the #EventLoop.
*
* This class is thread-safe.
*/
class
DeferEvent
final
:
DeferredMonitor
{
class
DeferEvent
final
{
friend
class
EventLoop
;
typedef
boost
::
intrusive
::
list_member_hook
<>
ListHook
;
ListHook
list_hook
;
EventLoop
&
loop
;
typedef
BoundMethod
<
void
()
noexcept
>
Callback
;
const
Callback
callback
;
public
:
DeferEvent
(
EventLoop
&
_loop
,
Callback
_callback
)
:
DeferredMonitor
(
_loop
),
callback
(
_callback
)
{}
DeferEvent
(
EventLoop
&
_loop
,
Callback
_callback
)
noexcept
:
loop
(
_loop
),
callback
(
_callback
)
{}
using
DeferredMonitor
::
GetEventLoop
;
using
DeferredMonitor
::
Schedule
;
using
DeferredMonitor
::
Cancel
;
~
DeferEvent
()
noexcept
{
Cancel
();
}
EventLoop
&
GetEventLoop
()
noexcept
{
return
loop
;
}
void
Schedule
()
noexcept
;
void
Cancel
()
noexcept
;
private
:
void
RunDeferred
()
noexcept
override
{
bool
IsPending
()
const
noexcept
{
return
list_hook
.
is_linked
();
}
void
RunDeferred
()
noexcept
{
callback
();
}
};
...
...
src/event/DeferredMonitor.hxx
deleted
100644 → 0
View file @
bf3ced6a
/*
* Copyright 2003-2017 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*
* 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.
*/
#ifndef MPD_SOCKET_DEFERRED_MONITOR_HXX
#define MPD_SOCKET_DEFERRED_MONITOR_HXX
#include "check.h"
#include <boost/intrusive/list_hook.hpp>
class
EventLoop
;
/**
* Defer execution of an event into an #EventLoop.
*
* This class is thread-safe.
*/
class
DeferredMonitor
{
friend
class
EventLoop
;
typedef
boost
::
intrusive
::
list_member_hook
<>
ListHook
;
ListHook
list_hook
;
EventLoop
&
loop
;
public
:
DeferredMonitor
(
EventLoop
&
_loop
)
:
loop
(
_loop
)
{}
~
DeferredMonitor
()
{
Cancel
();
}
EventLoop
&
GetEventLoop
()
{
return
loop
;
}
void
Schedule
();
void
Cancel
();
private
:
bool
IsPending
()
const
{
return
list_hook
.
is_linked
();
}
protected
:
virtual
void
RunDeferred
()
=
0
;
};
#endif
src/event/Loop.cxx
View file @
b57e2f55
...
...
@@ -21,7 +21,7 @@
#include "Loop.hxx"
#include "SocketMonitor.hxx"
#include "IdleMonitor.hxx"
#include "Defer
redMonitor
.hxx"
#include "Defer
Event
.hxx"
#include "util/ScopeExit.hxx"
EventLoop
::
EventLoop
(
ThreadId
_thread
)
...
...
@@ -163,7 +163,7 @@ EventLoop::Run()
return
;
}
/* try to handle Defer
redMonitor
s without WakeFD
/* try to handle Defer
Event
s without WakeFD
overhead */
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
...
...
@@ -211,7 +211,7 @@ EventLoop::Run()
}
void
EventLoop
::
AddDeferred
(
Defer
redMonitor
&
d
)
EventLoop
::
AddDeferred
(
Defer
Event
&
d
)
noexcept
{
bool
must_wake
;
...
...
@@ -221,7 +221,7 @@ EventLoop::AddDeferred(DeferredMonitor &d)
return
;
/* we don't need to wake up the EventLoop if another
Defer
redMonitor
has already done it */
Defer
Event
has already done it */
must_wake
=
!
busy
&&
deferred
.
empty
();
deferred
.
push_back
(
d
);
...
...
@@ -233,7 +233,7 @@ EventLoop::AddDeferred(DeferredMonitor &d)
}
void
EventLoop
::
RemoveDeferred
(
Defer
redMonitor
&
d
)
EventLoop
::
RemoveDeferred
(
Defer
Event
&
d
)
noexcept
{
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
...
...
@@ -245,7 +245,7 @@ void
EventLoop
::
HandleDeferred
()
{
while
(
!
deferred
.
empty
()
&&
!
quit
)
{
DeferredMonitor
&
m
=
deferred
.
front
();
auto
&
m
=
deferred
.
front
();
assert
(
m
.
IsPending
());
deferred
.
pop_front
();
...
...
src/event/Loop.hxx
View file @
b57e2f55
...
...
@@ -30,7 +30,7 @@
#include "SocketMonitor.hxx"
#include "TimerEvent.hxx"
#include "IdleMonitor.hxx"
#include "Defer
redMonitor
.hxx"
#include "Defer
Event
.hxx"
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/list.hpp>
...
...
@@ -76,10 +76,10 @@ class EventLoop final : SocketMonitor
Mutex
mutex
;
typedef
boost
::
intrusive
::
list
<
Defer
redMonitor
,
boost
::
intrusive
::
member_hook
<
Defer
redMonitor
,
Defer
redMonitor
::
ListHook
,
&
Defer
redMonitor
::
list_hook
>
,
typedef
boost
::
intrusive
::
list
<
Defer
Event
,
boost
::
intrusive
::
member_hook
<
Defer
Event
,
Defer
Event
::
ListHook
,
&
Defer
Event
::
list_hook
>
,
boost
::
intrusive
::
constant_time_size
<
false
>>
DeferredList
;
DeferredList
deferred
;
...
...
@@ -160,19 +160,19 @@ public:
void
CancelTimer
(
TimerEvent
&
t
);
/**
* Schedule a call to Defer
redMonitor
::RunDeferred().
* Schedule a call to Defer
Event
::RunDeferred().
*
* This method is thread-safe.
*/
void
AddDeferred
(
Defer
redMonitor
&
d
)
;
void
AddDeferred
(
Defer
Event
&
d
)
noexcept
;
/**
* Cancel a pending call to Defer
redMonitor
::RunDeferred().
* Cancel a pending call to Defer
Event
::RunDeferred().
* However after returning, the call may still be running.
*
* This method is thread-safe.
*/
void
RemoveDeferred
(
Defer
redMonitor
&
d
)
;
void
RemoveDeferred
(
Defer
Event
&
d
)
noexcept
;
/**
* The main function of this class. It will loop until
...
...
@@ -182,7 +182,7 @@ public:
private
:
/**
* Invoke all pending Defer
redMonitor
s.
* Invoke all pending Defer
Event
s.
*
* Caller must lock the mutex.
*/
...
...
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