diff options
| author | Jeff Cohen <jeffc@jolt-lang.org> | 2005-08-02 03:04:47 +0000 | 
|---|---|---|
| committer | Jeff Cohen <jeffc@jolt-lang.org> | 2005-08-02 03:04:47 +0000 | 
| commit | ba7cc685942759b8eb406c2f35834dc619ea45d1 (patch) | |
| tree | 151e58e62acca49a8254b3607a0df2f5657a8880 /llvm | |
| parent | 75a44e154e3683a301761ec88216b9e494919a7f (diff) | |
| download | bcm5719-llvm-ba7cc685942759b8eb406c2f35834dc619ea45d1.tar.gz bcm5719-llvm-ba7cc685942759b8eb406c2f35834dc619ea45d1.zip  | |
Implement SetInterruptFunction for Windows.
llvm-svn: 22582
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/System/Signals.h | 3 | ||||
| -rw-r--r-- | llvm/lib/System/Win32/Signals.inc | 26 | 
2 files changed, 27 insertions, 2 deletions
diff --git a/llvm/include/llvm/System/Signals.h b/llvm/include/llvm/System/Signals.h index f29fae9ab54..1d5286f3bd9 100644 --- a/llvm/include/llvm/System/Signals.h +++ b/llvm/include/llvm/System/Signals.h @@ -42,7 +42,8 @@ namespace sys {    /// being killed, and the interrupt function automatically disabled.  Note    /// that interrupt functions are not allowed to call any non-reentrant    /// functions.  An null interrupt function pointer disables the current -  /// installed function. +  /// installed function.  Note also that the handler may be executed on a +  /// different thread on some platforms.    /// @brief Register a function to be called when ctrl-c is pressed.    void SetInterruptFunction(void (*IF)());  } // End sys namespace diff --git a/llvm/lib/System/Win32/Signals.inc b/llvm/lib/System/Win32/Signals.inc index a2c7ae2c307..cf5cb40d4d0 100644 --- a/llvm/lib/System/Win32/Signals.inc +++ b/llvm/lib/System/Win32/Signals.inc @@ -29,6 +29,9 @@  static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep);  static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); +// InterruptFunction - The function to call if ctrl-c is pressed. +static void (*InterruptFunction)() = 0; +  static std::vector<llvm::sys::Path> *FilesToRemove = NULL;  static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;  static bool RegisteredUnhandledExceptionFilter = false; @@ -111,7 +114,9 @@ void sys::PrintStackTraceOnErrorSignal() {  void sys::SetInterruptFunction(void (*IF)()) { -  // Currently unimplemented. +  InterruptFunction = IF; +  RegisterHandler(); +  LeaveCriticalSection(&CriticalSection);  }  } @@ -234,9 +239,28 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {  }  static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { +  EnterCriticalSection(&CriticalSection);    Cleanup(); +  // If an interrupt function has been set, go and run one it; otherwise, +  // the process dies. +  void (*IF)() = InterruptFunction; +  InterruptFunction = 0;      // Don't run it on another CTRL-C. + +  if (IF) { +    try { +      IF();                   // Run it now. +    } catch (...) { +      // Kill the process on an exception. +      LeaveCriticalSection(&CriticalSection); +      return FALSE; +    } +    LeaveCriticalSection(&CriticalSection); +    return TRUE;              // Don't kill the process. +  } +    // Allow normal processing to take place; i.e., the process dies. +  LeaveCriticalSection(&CriticalSection);    return FALSE;  }  | 

