#include "Unix.h"
#include "llvm/ADT/STLExtras.h"
#include "Unix.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/System/Mutex.h"
#include <vector>
#include <algorithm>
#if HAVE_EXECINFO_H
#include <vector>
#include <algorithm>
#if HAVE_EXECINFO_H
static RETSIGTYPE SignalHandler(int Sig); // defined below.
static RETSIGTYPE SignalHandler(int Sig); // defined below.
+static SmartMutex<true> SignalsMutex;
+
/// InterruptFunction - The function to call if ctrl-c is pressed.
static void (*InterruptFunction)() = 0;
/// InterruptFunction - The function to call if ctrl-c is pressed.
static void (*InterruptFunction)() = 0;
sigfillset(&SigMask);
sigprocmask(SIG_UNBLOCK, &SigMask, 0);
sigfillset(&SigMask);
sigprocmask(SIG_UNBLOCK, &SigMask, 0);
+ SignalsMutex.acquire();
if (FilesToRemove != 0)
while (!FilesToRemove->empty()) {
FilesToRemove->back().eraseFromDisk(true);
if (FilesToRemove != 0)
while (!FilesToRemove->empty()) {
FilesToRemove->back().eraseFromDisk(true);
if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) {
if (InterruptFunction) {
void (*IF)() = InterruptFunction;
if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) {
if (InterruptFunction) {
void (*IF)() = InterruptFunction;
+ SignalsMutex.release();
InterruptFunction = 0;
IF(); // run the interrupt function.
return;
}
InterruptFunction = 0;
IF(); // run the interrupt function.
return;
}
+
+ SignalsMutex.release();
raise(Sig); // Execute the default handler.
return;
}
raise(Sig); // Execute the default handler.
return;
}
+ SignalsMutex.release();
+
// Otherwise if it is a fault (like SEGV) run any handler.
if (CallBacksToRun)
for (unsigned i = 0, e = CallBacksToRun->size(); i != e; ++i)
// Otherwise if it is a fault (like SEGV) run any handler.
if (CallBacksToRun)
for (unsigned i = 0, e = CallBacksToRun->size(); i != e; ++i)
void llvm::sys::SetInterruptFunction(void (*IF)()) {
void llvm::sys::SetInterruptFunction(void (*IF)()) {
+ SignalsMutex.acquire();
+ SignalsMutex.release();
RegisterHandlers();
}
// RemoveFileOnSignal - The public API
bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename,
std::string* ErrMsg) {
RegisterHandlers();
}
// RemoveFileOnSignal - The public API
bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename,
std::string* ErrMsg) {
+ SignalsMutex.acquire();
if (FilesToRemove == 0)
FilesToRemove = new std::vector<sys::Path>();
FilesToRemove->push_back(Filename);
if (FilesToRemove == 0)
FilesToRemove = new std::vector<sys::Path>();
FilesToRemove->push_back(Filename);
+ SignalsMutex.release();
+
RegisterHandlers();
return false;
}
RegisterHandlers();
return false;
}