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 | 298d6c14ca1936677aaf6cca3efc569b6e53d294 (patch) | |
tree | f501e28b69ac0f0e7328c0f728da9be7accf9cb9 /lib/System | |
parent | f2b2d86d6bf9aba5b58833c291320b31f0840c09 (diff) | |
download | external_llvm-298d6c14ca1936677aaf6cca3efc569b6e53d294.zip external_llvm-298d6c14ca1936677aaf6cca3efc569b6e53d294.tar.gz external_llvm-298d6c14ca1936677aaf6cca3efc569b6e53d294.tar.bz2 |
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!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16383 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Win32/Signals.cpp | 13 | ||||
-rw-r--r-- | lib/System/Win32/Signals.inc | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/System/Win32/Signals.cpp b/lib/System/Win32/Signals.cpp index d1bd2e8..130d3d6 100644 --- a/lib/System/Win32/Signals.cpp +++ b/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; } diff --git a/lib/System/Win32/Signals.inc b/lib/System/Win32/Signals.inc index d1bd2e8..130d3d6 100644 --- a/lib/System/Win32/Signals.inc +++ b/lib/System/Win32/Signals.inc @@ -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; } |