mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
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
This commit is contained in:
@@ -28,6 +28,10 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType);
|
|||||||
static std::vector<std::string> *FilesToRemove = NULL;
|
static std::vector<std::string> *FilesToRemove = NULL;
|
||||||
static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
|
static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
|
||||||
static bool RegisteredUnhandledExceptionFilter = false;
|
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;
|
static CRITICAL_SECTION CriticalSection;
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@@ -40,7 +44,10 @@ namespace llvm {
|
|||||||
|
|
||||||
static void RegisterHandler() {
|
static void RegisterHandler() {
|
||||||
if (RegisteredUnhandledExceptionFilter)
|
if (RegisteredUnhandledExceptionFilter)
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&CriticalSection);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Now's the time to create the critical section. This is the first time
|
// Now's the time to create the critical section. This is the first time
|
||||||
// through here, and there's only one thread.
|
// 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) {
|
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();
|
Cleanup();
|
||||||
|
|
||||||
// Allow normal processing to take place.
|
// Allow normal processing to take place; i.e., the process dies.
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,10 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType);
|
|||||||
static std::vector<std::string> *FilesToRemove = NULL;
|
static std::vector<std::string> *FilesToRemove = NULL;
|
||||||
static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
|
static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
|
||||||
static bool RegisteredUnhandledExceptionFilter = false;
|
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;
|
static CRITICAL_SECTION CriticalSection;
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@@ -40,7 +44,10 @@ namespace llvm {
|
|||||||
|
|
||||||
static void RegisterHandler() {
|
static void RegisterHandler() {
|
||||||
if (RegisteredUnhandledExceptionFilter)
|
if (RegisteredUnhandledExceptionFilter)
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&CriticalSection);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Now's the time to create the critical section. This is the first time
|
// Now's the time to create the critical section. This is the first time
|
||||||
// through here, and there's only one thread.
|
// 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) {
|
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();
|
Cleanup();
|
||||||
|
|
||||||
// Allow normal processing to take place.
|
// Allow normal processing to take place; i.e., the process dies.
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user