mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
factorize signal registration, part of PR3848.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67508 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3aff0a63f9
commit
1c4d8a00ab
@ -31,6 +31,8 @@
|
|||||||
#endif
|
#endif
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static RETSIGTYPE SignalHandler(int Sig); // defined below.
|
||||||
|
|
||||||
/// InterruptFunction - The function to call if ctrl-c is pressed.
|
/// InterruptFunction - The function to call if ctrl-c is pressed.
|
||||||
static void (*InterruptFunction)() = 0;
|
static void (*InterruptFunction)() = 0;
|
||||||
|
|
||||||
@ -55,10 +57,26 @@ static const int KillSigs[] = {
|
|||||||
static const int *const KillSigsEnd =
|
static const int *const KillSigsEnd =
|
||||||
KillSigs + sizeof(KillSigs) / sizeof(KillSigs[0]);
|
KillSigs + sizeof(KillSigs) / sizeof(KillSigs[0]);
|
||||||
|
|
||||||
static void UnregisterHandler(int Signal) {
|
// Just call signal
|
||||||
signal(Signal, SIG_DFL);
|
static void RegisterHandler(int Signal) {
|
||||||
|
signal(Signal, SignalHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RegisterHandlers() {
|
||||||
|
std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
|
||||||
|
std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UnregisterHandler(int Signal) {
|
||||||
|
signal(Signal, SIG_DFL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UnregisterHandlers() {
|
||||||
|
std::for_each(KillSigs, KillSigsEnd, UnregisterHandler);
|
||||||
|
std::for_each(IntSigs, IntSigsEnd, UnregisterHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// SignalHandler - The signal handler that runs.
|
// SignalHandler - The signal handler that runs.
|
||||||
static RETSIGTYPE SignalHandler(int Sig) {
|
static RETSIGTYPE SignalHandler(int Sig) {
|
||||||
@ -66,7 +84,7 @@ static RETSIGTYPE SignalHandler(int Sig) {
|
|||||||
// crashes when we return and the signal reissues. This also ensures that if
|
// crashes when we return and the signal reissues. This also ensures that if
|
||||||
// we crash in our signal handler that the program will terminate immediately
|
// we crash in our signal handler that the program will terminate immediately
|
||||||
// instead of recursing in the signal handler.
|
// instead of recursing in the signal handler.
|
||||||
std::for_each(KillSigs, KillSigsEnd, UnregisterHandler);
|
UnregisterHandlers();
|
||||||
|
|
||||||
// Unmask all potentially blocked kill signals.
|
// Unmask all potentially blocked kill signals.
|
||||||
sigset_t SigMask;
|
sigset_t SigMask;
|
||||||
@ -95,15 +113,11 @@ static RETSIGTYPE SignalHandler(int Sig) {
|
|||||||
(*CallBacksToRun)[i].first((*CallBacksToRun)[i].second);
|
(*CallBacksToRun)[i].first((*CallBacksToRun)[i].second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just call signal
|
|
||||||
static void RegisterHandler(int Signal) {
|
|
||||||
signal(Signal, SignalHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void llvm::sys::SetInterruptFunction(void (*IF)()) {
|
void llvm::sys::SetInterruptFunction(void (*IF)()) {
|
||||||
InterruptFunction = IF;
|
InterruptFunction = IF;
|
||||||
RegisterHandler(SIGINT);
|
RegisterHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveFileOnSignal - The public API
|
// RemoveFileOnSignal - The public API
|
||||||
@ -114,8 +128,7 @@ bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename,
|
|||||||
|
|
||||||
FilesToRemove->push_back(Filename);
|
FilesToRemove->push_back(Filename);
|
||||||
|
|
||||||
std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
|
RegisterHandlers();
|
||||||
std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +139,7 @@ void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) {
|
|||||||
if (CallBacksToRun == 0)
|
if (CallBacksToRun == 0)
|
||||||
CallBacksToRun = new std::vector<std::pair<void(*)(void*), void*> >();
|
CallBacksToRun = new std::vector<std::pair<void(*)(void*), void*> >();
|
||||||
CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie));
|
CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie));
|
||||||
std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
|
RegisterHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user