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
4280f845
Commit
4280f845
authored
Jun 20, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/SignalMonitor: use BoundMethod instead of raw function pointer
parent
c3d9c326
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
14 deletions
+18
-14
SignalMonitor.cxx
src/event/SignalMonitor.cxx
+3
-3
SignalMonitor.hxx
src/event/SignalMonitor.hxx
+3
-1
SignalHandlers.cxx
src/unix/SignalHandlers.cxx
+7
-6
ShutdownHandler.cxx
test/ShutdownHandler.cxx
+5
-4
No files found.
src/event/SignalMonitor.cxx
View file @
4280f845
...
...
@@ -158,7 +158,7 @@ SignalMonitorFinish()
sa
.
sa_handler
=
SIG_DFL
;
for
(
unsigned
i
=
0
;
i
<
MAX_SIGNAL
;
++
i
)
{
if
(
signal_handlers
[
i
]
!=
nullptr
)
{
if
(
signal_handlers
[
i
])
{
x_sigaction
(
i
,
sa
);
signal_handlers
[
i
]
=
nullptr
;
}
...
...
@@ -179,7 +179,7 @@ SignalMonitorGetEventLoop()
void
SignalMonitorRegister
(
int
signo
,
SignalHandler
handler
)
{
assert
(
signal_handlers
[
signo
]
==
nullptr
);
assert
(
!
signal_handlers
[
signo
]
);
#ifndef USE_SIGNALFD
assert
(
!
signal_pending
[
signo
]);
#endif
...
...
@@ -209,7 +209,7 @@ SignalMonitor::OnSocketReady(unsigned)
int
signo
;
while
((
signo
=
fd
.
Read
())
>=
0
)
{
assert
(
unsigned
(
signo
)
<
MAX_SIGNAL
);
assert
(
signal_handlers
[
signo
]
!=
nullptr
);
assert
(
signal_handlers
[
signo
]);
signal_handlers
[
signo
]();
}
...
...
src/event/SignalMonitor.hxx
View file @
4280f845
...
...
@@ -26,7 +26,9 @@ class EventLoop;
#ifndef WIN32
typedef
void
(
*
SignalHandler
)();
#include "util/BindMethod.hxx"
typedef
BoundMethod
<
void
()
>
SignalHandler
;
/**
* Initialise the signal monitor subsystem.
...
...
src/unix/SignalHandlers.cxx
View file @
4280f845
...
...
@@ -34,9 +34,10 @@
static
constexpr
Domain
signal_handlers_domain
(
"signal_handlers"
);
static
void
HandleShutdownSignal
()
HandleShutdownSignal
(
void
*
ctx
)
{
SignalMonitorGetEventLoop
().
Break
();
auto
&
loop
=
*
(
EventLoop
*
)
ctx
;
loop
.
Break
();
}
static
void
...
...
@@ -47,7 +48,7 @@ x_sigaction(int signum, const struct sigaction *act)
}
static
void
handle_reload_event
(
void
)
handle_reload_event
(
void
*
)
{
LogDebug
(
signal_handlers_domain
,
"got SIGHUP, reopening log files"
);
cycle_log_files
();
...
...
@@ -68,10 +69,10 @@ SignalHandlersInit(EventLoop &loop)
sa
.
sa_handler
=
SIG_IGN
;
x_sigaction
(
SIGPIPE
,
&
sa
);
SignalMonitorRegister
(
SIGINT
,
HandleShutdownSignal
);
SignalMonitorRegister
(
SIGTERM
,
HandleShutdownSignal
);
SignalMonitorRegister
(
SIGINT
,
{
&
loop
,
HandleShutdownSignal
}
);
SignalMonitorRegister
(
SIGTERM
,
{
&
loop
,
HandleShutdownSignal
}
);
SignalMonitorRegister
(
SIGHUP
,
handle_reload_event
);
SignalMonitorRegister
(
SIGHUP
,
{
nullptr
,
handle_reload_event
}
);
#endif
}
...
...
test/ShutdownHandler.cxx
View file @
4280f845
...
...
@@ -27,17 +27,18 @@
#include <signal.h>
static
void
HandleShutdownSignal
()
HandleShutdownSignal
(
void
*
ctx
)
{
SignalMonitorGetEventLoop
().
Break
();
auto
&
loop
=
*
(
EventLoop
*
)
ctx
;
loop
.
Break
();
}
ShutdownHandler
::
ShutdownHandler
(
EventLoop
&
loop
)
{
SignalMonitorInit
(
loop
);
SignalMonitorRegister
(
SIGINT
,
HandleShutdownSignal
);
SignalMonitorRegister
(
SIGTERM
,
HandleShutdownSignal
);
SignalMonitorRegister
(
SIGINT
,
{
&
loop
,
HandleShutdownSignal
}
);
SignalMonitorRegister
(
SIGTERM
,
{
&
loop
,
HandleShutdownSignal
}
);
}
ShutdownHandler
::~
ShutdownHandler
()
...
...
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