]> gitweb.factorcode.org Git - factor.git/commitdiff
win32 main starts factorvm in new thread
authorPhil Dawes <phil@phildawes.net>
Mon, 24 Aug 2009 20:10:18 +0000 (21:10 +0100)
committerPhil Dawes <phil@phildawes.net>
Wed, 16 Sep 2009 07:20:09 +0000 (08:20 +0100)
vm/factor.cpp
vm/factor.hpp
vm/os-windows-nt.cpp

index bb30aae7ee8616a8a212bafd5cbbac13814f033d..77ad60bd474893540f3b161dd853f5aba88238d3 100755 (executable)
@@ -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);
index fbd6873c2893510b39c787b913cb3215b2e18b2e..b824758c8a41ea126e92a3c855f1dfddfbbcdd45 100644 (file)
@@ -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);
-
 }
index b212287e5feda6d44fc34a62f7e8ebc6b77249ac..c36c2f3f7eb912496a6665d50bcd18fa2f4d704e 100755 (executable)
@@ -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()