diff options
Diffstat (limited to 'src/pkg/runtime/windows/thread.c')
-rw-r--r-- | src/pkg/runtime/windows/thread.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/pkg/runtime/windows/thread.c b/src/pkg/runtime/windows/thread.c index 278a5da69..aedd24200 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); } @@ -180,11 +184,17 @@ runtime·notesleep(Note *n) void runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void)) { + void *thandle; + USED(stk); USED(g); // assuming g = m->g0 USED(fn); // assuming fn = mstart - runtime·stdcall(runtime·CreateThread, 6, 0, 0, runtime·tstart_stdcall, m, 0, 0); + thandle = runtime·stdcall(runtime·CreateThread, 6, 0, 0, runtime·tstart_stdcall, m, 0, 0); + if(thandle == 0) { + runtime·printf("runtime: failed to create new OS thread (have %d already; errno=%d)\n", runtime·mcount(), runtime·getlasterror()); + runtime·throw("runtime.newosproc"); + } } // Called to initialize a new m (including the bootstrap m). @@ -279,6 +289,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) |