From e201c07d2305dc9a3609ba4feb95336000dc71e6 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 1 Sep 2010 14:17:34 +0000 Subject: [PATCH] Add an interface for unregistering a file from the FilesToRemove list. llvm-svn: 112705 --- llvm/include/llvm/System/Signals.h | 4 ++++ llvm/lib/System/Unix/Signals.inc | 10 ++++++++++ llvm/lib/System/Win32/Signals.inc | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/llvm/include/llvm/System/Signals.h b/llvm/include/llvm/System/Signals.h index 504420cd402d..7f1c87c3d55a 100644 --- a/llvm/include/llvm/System/Signals.h +++ b/llvm/include/llvm/System/Signals.h @@ -29,6 +29,10 @@ namespace sys { /// @brief Remove a file if a fatal signal occurs. bool RemoveFileOnSignal(const Path &Filename, std::string* ErrMsg = 0); + /// This function removes a file from the list of files to be removed on + /// signal delivery. + void DontRemoveFileOnSignal(const Path &Filename); + /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the /// process, print a stack trace and then exit. /// @brief Print a stack trace if a fatal signal occurs. diff --git a/llvm/lib/System/Unix/Signals.inc b/llvm/lib/System/Unix/Signals.inc index 3e0de66b5d71..7b7c43efc786 100644 --- a/llvm/lib/System/Unix/Signals.inc +++ b/llvm/lib/System/Unix/Signals.inc @@ -182,6 +182,16 @@ bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename, return false; } +// DontRemoveFileOnSignal - The public API +void llvm::sys::DontRemoveFileOnSignal(const sys::Path &Filename) { + SignalsMutex.acquire(); + std::vector::reverse_iterator I = + std::find(FilesToRemove.rbegin(), FilesToRemove.rend(), Filename); + if (I != FilesToRemove.rend()) + FilesToRemove.erase(I.base()-1); + SignalsMutex.release(); +} + /// AddSignalHandler - Add a function to be called when a signal is delivered /// to the process. The handler can have a cookie passed to it to identify /// what instance of the handler it is. diff --git a/llvm/lib/System/Win32/Signals.inc b/llvm/lib/System/Win32/Signals.inc index d6db71ba4f35..2498a26ea99c 100644 --- a/llvm/lib/System/Win32/Signals.inc +++ b/llvm/lib/System/Win32/Signals.inc @@ -140,6 +140,20 @@ bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) { return false; } +// DontRemoveFileOnSignal - The public API +void sys::DontRemoveFileOnSignal(const sys::Path &Filename) { + if (FilesToRemove == NULL) + return; + + FilesToRemove->push_back(Filename); + std::vector::reverse_iterator I = + std::find(FilesToRemove->rbegin(), FilesToRemove->rend(), Filename); + if (I != FilesToRemove->rend()) + FilesToRemove->erase(I.base()-1); + + LeaveCriticalSection(&CriticalSection); +} + /// PrintStackTraceOnErrorSignal - When an error signal (such as SIBABRT or /// SIGSEGV) is delivered to the process, print a stack trace and then exit. void sys::PrintStackTraceOnErrorSignal() {