diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-09-17 03:02:27 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-09-17 03:02:27 +0000 |
commit | 90debc5e2ee994c0669d3cd62d83bad6539c735d (patch) | |
tree | ffe871522f45751f99d063cd405cb577704b1b92 | |
parent | 7cd7aeee9a82e00e8ca67668e525a5f103d607a4 (diff) | |
download | bcm5719-llvm-90debc5e2ee994c0669d3cd62d83bad6539c735d.tar.gz bcm5719-llvm-90debc5e2ee994c0669d3cd62d83bad6539c735d.zip |
Make sure critical sections are entered before trying to leave them.
Add some additional commentary about the workings of this module.
Patch contributed by Jeff Cohen. Thanks Jeff!
llvm-svn: 16383
-rw-r--r-- | llvm/lib/System/Win32/Signals.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/System/Win32/Signals.cpp b/llvm/lib/System/Win32/Signals.cpp index d1bd2e84e04..130d3d63a18 100644 --- a/llvm/lib/System/Win32/Signals.cpp +++ b/llvm/lib/System/Win32/Signals.cpp @@ -28,6 +28,10 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); static std::vector<std::string> *FilesToRemove = NULL; static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL; static bool RegisteredUnhandledExceptionFilter = false; + +// Windows creates a new thread to execute the console handler when an event +// (such as CTRL/C) occurs. This causes concurrency issues with the above +// globals which this critical section addresses. static CRITICAL_SECTION CriticalSection; namespace llvm { @@ -40,7 +44,10 @@ namespace llvm { static void RegisterHandler() { if (RegisteredUnhandledExceptionFilter) + { + EnterCriticalSection(&CriticalSection); return; + } // Now's the time to create the critical section. This is the first time // through here, and there's only one thread. @@ -205,9 +212,13 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { } static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { + // FIXME: This handler executes on a different thread. The main thread + // is still running, potentially creating new files to be cleaned up + // in the tiny window between the call to Cleanup() and process termination. + // Also, any files currently open cannot be deleted. Cleanup(); - // Allow normal processing to take place. + // Allow normal processing to take place; i.e., the process dies. return FALSE; } |