diff options
| author | Hector Chu <hectorchu@gmail.com> | 2011-02-14 12:15:13 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-02-14 12:15:13 -0500 |
| commit | 1723fbe13e9288f1dff1da90df6fd6922f941975 (patch) | |
| tree | 8592948f31eac4f859b8d610bd88162af698d9f4 /src/pkg/runtime/windows/thread.c | |
| parent | b9f94768f90dfc7f5d4bf7cf9ccf64b9190d0e93 (diff) | |
| download | go-1723fbe13e9288f1dff1da90df6fd6922f941975.tar.xz | |
windows: runtime: implemented console ctrl handler (SIGINT).
R=rsc, brainman, iant2
CC=golang-dev
https://golang.org/cl/4129049
Diffstat (limited to 'src/pkg/runtime/windows/thread.c')
| -rw-r--r-- | src/pkg/runtime/windows/thread.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/pkg/runtime/windows/thread.c b/src/pkg/runtime/windows/thread.c index 278a5da692..525fd09801 100644 --- a/src/pkg/runtime/windows/thread.c +++ b/src/pkg/runtime/windows/thread.c @@ -18,6 +18,7 @@ #pragma dynimport runtime·LoadLibraryEx LoadLibraryExA "kernel32.dll" #pragma dynimport runtime·QueryPerformanceCounter QueryPerformanceCounter "kernel32.dll" #pragma dynimport runtime·QueryPerformanceFrequency QueryPerformanceFrequency "kernel32.dll" +#pragma dynimport runtime·SetConsoleCtrlHandler SetConsoleCtrlHandler "kernel32.dll" #pragma dynimport runtime·SetEvent SetEvent "kernel32.dll" #pragma dynimport runtime·WaitForSingleObject WaitForSingleObject "kernel32.dll" #pragma dynimport runtime·WriteFile WriteFile "kernel32.dll" @@ -33,6 +34,7 @@ extern void *runtime·GetStdHandle; extern void *runtime·LoadLibraryEx; extern void *runtime·QueryPerformanceCounter; extern void *runtime·QueryPerformanceFrequency; +extern void *runtime·SetConsoleCtrlHandler; extern void *runtime·SetEvent; extern void *runtime·WaitForSingleObject; extern void *runtime·WriteFile; @@ -43,6 +45,7 @@ void runtime·osinit(void) { runtime·stdcall(runtime·QueryPerformanceFrequency, 1, &timerfreq); + runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, 1); } void @@ -161,6 +164,7 @@ runtime·destroylock(Lock *l) void runtime·noteclear(Note *n) { + n->lock.key = 0; // memset(n, 0, sizeof *n) eventlock(&n->lock); } @@ -279,6 +283,41 @@ runtime·sigpanic(void) runtime·throw("fault"); } +String +runtime·signame(int32 sig) +{ + int8 *s; + + switch(sig) { + case SIGINT: + s = "SIGINT: interrupt"; + break; + default: + return runtime·emptystring; + } + return runtime·gostringnocopy((byte*)s); +} + +uint32 +runtime·ctrlhandler1(uint32 type) +{ + int32 s; + + switch(type) { + case CTRL_C_EVENT: + case CTRL_BREAK_EVENT: + s = SIGINT; + break; + default: + return 0; + } + + if(runtime·sigsend(s)) + return 1; + runtime·exit(2); // SIGINT, SIGTERM, etc + return 0; +} + // Call back from windows dll into go. byte * runtime·compilecallback(Eface fn, bool cleanstack) |
