summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorJF Bastien <jfb@google.com>2018-05-15 04:23:48 +0000
committerJF Bastien <jfb@google.com>2018-05-15 04:23:48 +0000
commit9f62b4c8a8080397d677a418a32527f4ce8a0dbd (patch)
tree59cce5644c910e977591a51857831230f628b5ae /llvm/lib/Support
parent58fdb3b09aae005c594ea66bfb85b395d7193636 (diff)
downloadbcm5719-llvm-9f62b4c8a8080397d677a418a32527f4ce8a0dbd.tar.gz
bcm5719-llvm-9f62b4c8a8080397d677a418a32527f4ce8a0dbd.zip
[NFC] pull a function into its own lambda
As requested in D46858, pulling this function into its own lambda makes it easier to read that part of the code and reason as to what's going on because the scope it can be called from is extremely limited. We want to keep it as a function because it's called from the two subsequent lines. llvm-svn: 332325
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Unix/Signals.inc40
1 files changed, 21 insertions, 19 deletions
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 33edc2a5d4d..d828674de49 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -101,23 +101,6 @@ static struct {
} RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)];
-static void RegisterHandler(int Signal) {
- assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) &&
- "Out of space for signal handlers!");
-
- struct sigaction NewHandler;
-
- NewHandler.sa_handler = SignalHandler;
- NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
- sigemptyset(&NewHandler.sa_mask);
-
- // Install the new handler, save the old one in RegisteredSignalInfo.
- sigaction(Signal, &NewHandler,
- &RegisteredSignalInfo[NumRegisteredSignals].SA);
- RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal;
- ++NumRegisteredSignals;
-}
-
#if defined(HAVE_SIGALTSTACK)
// Hold onto both the old and new alternate signal stack so that it's not
// reported as a leak. We don't make any attempt to remove our alt signal
@@ -159,8 +142,27 @@ static void RegisterHandlers() {
// be able to reliably handle signals due to stack overflow.
CreateSigAltStack();
- for (auto S : IntSigs) RegisterHandler(S);
- for (auto S : KillSigs) RegisterHandler(S);
+ auto registerHandler = [&](int Signal) {
+ assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) &&
+ "Out of space for signal handlers!");
+
+ struct sigaction NewHandler;
+
+ NewHandler.sa_handler = SignalHandler;
+ NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
+ sigemptyset(&NewHandler.sa_mask);
+
+ // Install the new handler, save the old one in RegisteredSignalInfo.
+ sigaction(Signal, &NewHandler,
+ &RegisteredSignalInfo[NumRegisteredSignals].SA);
+ RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal;
+ ++NumRegisteredSignals;
+ };
+
+ for (auto S : IntSigs)
+ registerHandler(S);
+ for (auto S : KillSigs)
+ registerHandler(S);
}
static void UnregisterHandlers() {
OpenPOWER on IntegriCloud