From aa005c948f8aadf91f218935d9bd1cb01977787a Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Mon, 24 Aug 2009 21:10:18 +0100 Subject: [PATCH] win32 main starts factorvm in new thread --- vm/factor.cpp | 4 ++-- vm/factor.hpp | 1 - vm/os-windows-nt.cpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vm/factor.cpp b/vm/factor.cpp index bb30aae7ee..77ad60bd47 100755 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -170,8 +170,9 @@ void factorvm::pass_args_to_factor(int argc, vm_char **argv) growable_array args(this); int i; - for(i = 1; i < argc; i++) + for(i = 1; i < argc; i++){ args.add(allot_alien(F,(cell)argv[i])); + } args.trim(); userenv[ARGS_ENV] = args.elements.value(); @@ -212,7 +213,6 @@ void factorvm::factor_sleep(long us) void factorvm::start_standalone_factor(int argc, vm_char **argv) { - //printf("thread id is %d\n",GetCurrentThreadId());fflush(stdout); register_vm(GetCurrentThreadId(),this); vm_parameters p; default_parameters(&p); diff --git a/vm/factor.hpp b/vm/factor.hpp index fbd6873c28..b824758c8a 100644 --- a/vm/factor.hpp +++ b/vm/factor.hpp @@ -3,5 +3,4 @@ namespace factor VM_C_API void start_standalone_factor(int argc, vm_char **argv); VM_C_API void *start_standalone_factor_in_new_thread(int argc, vm_char **argv); - } diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index b212287e5f..c36c2f3f7e 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -18,7 +18,6 @@ s64 factorvm::current_micros() FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe) { - //printf("exception handler %d\n",GetCurrentThreadId());fflush(stdout); factorvm *myvm = lookup_vm(GetCurrentThreadId()); PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord; CONTEXT *c = (CONTEXT*)pe->ContextRecord; @@ -64,12 +63,17 @@ FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe) return EXCEPTION_CONTINUE_EXECUTION; } +bool handler_added = 0; + void factorvm::c_to_factor_toplevel(cell quot) { - if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)exception_handler)) - fatal_error("AddVectoredExceptionHandler failed", 0); + if(!handler_added){ + if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)exception_handler)) + fatal_error("AddVectoredExceptionHandler failed", 0); + handler_added = 1; + } c_to_factor(quot,this); - RemoveVectoredExceptionHandler((void *)exception_handler); + RemoveVectoredExceptionHandler((void *)exception_handler); } void factorvm::open_console()