diff --git a/vm/factor.cpp b/vm/factor.cpp index 77ad60bd47..a241ccf86b 100755 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -213,7 +213,7 @@ void factorvm::factor_sleep(long us) void factorvm::start_standalone_factor(int argc, vm_char **argv) { - register_vm(GetCurrentThreadId(),this); + register_vm(thread_id(),this); vm_parameters p; default_parameters(&p); init_parameters_from_args(&p,argc,argv); @@ -247,8 +247,7 @@ VM_C_API void *start_standalone_factor_in_new_thread(int argc, vm_char **argv) { startargs *args = new startargs; // leaks startargs structure args->argc = argc; args->argv = argv; - void *handle = start_thread(start_standalone_factor_thread,args); - return handle; + return start_thread(start_standalone_factor_thread,args); } } diff --git a/vm/mach_signal.cpp b/vm/mach_signal.cpp index ca3b7aa161..c1d263527d 100644 --- a/vm/mach_signal.cpp +++ b/vm/mach_signal.cpp @@ -215,7 +215,7 @@ void mach_initialize () mask = EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC; /* Create the thread listening on the exception port. */ - start_thread(mach_exception_thread); + start_thread(mach_exception_thread,NULL); /* Replace the exception port info for these exceptions with our own. Note that we replace the exception port for the entire task, not only diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index 97e1e0c04d..4de5ede704 100644 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -3,18 +3,18 @@ namespace factor { -void start_thread(void *(*start_routine)(void *)) +void *start_thread(void *(*start_routine)(void *),void *args) { pthread_attr_t attr; pthread_t thread; - if (pthread_attr_init (&attr) != 0) vm->fatal_error("pthread_attr_init() failed",0); if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0) vm->fatal_error("pthread_attr_setdetachstate() failed",0); - if (pthread_create (&thread, &attr, start_routine, NULL) != 0) + if (pthread_create (&thread, &attr, start_routine, args) != 0) vm->fatal_error("pthread_create() failed",0); pthread_attr_destroy (&attr); + return (void*)thread; } static void *null_dll; @@ -55,13 +55,24 @@ void ffi_dlclose(dll *dll) dll->dll = NULL; } -PRIMITIVE(existsp) + +long factorvm::thread_id(){ + return 0; // TODO fix me +} + + +inline void factorvm::vmprim_existsp() { struct stat sb; char *path = (char *)(vm->untag_check(dpop()) + 1); box_boolean(stat(path,&sb) >= 0); } +PRIMITIVE(existsp) +{ + PRIMITIVE_GETVM()->vmprim_existsp(); +} + segment *alloc_segment(cell size) { int pagesize = getpagesize(); @@ -320,7 +331,7 @@ void open_console() stdin_read = filedes[0]; stdin_write = filedes[1]; - start_thread(stdin_loop); + start_thread(stdin_loop,NULL); } VM_C_API void wait_for_stdin() diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index b7e528a421..60beb88233 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -42,7 +42,7 @@ typedef char symbol_char; #define print_native_string(string) print_string(string) -void start_thread(void *(*start_routine)(void *)); +void *start_thread(void *(*start_routine)(void *),void *args); void init_ffi(); void ffi_dlopen(dll *dll); diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index c36c2f3f7e..6085d65670 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -7,6 +7,10 @@ void *start_thread(void *(*start_routine)(void *),void *args){ return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, args, 0, 0); } +long factorvm::thread_id(){ + return GetCurrentThreadId(); +} + s64 factorvm::current_micros() { diff --git a/vm/vm.hpp b/vm/vm.hpp index b3e40640b7..384c98186a 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -669,6 +669,12 @@ struct factorvm { void print_fixnum(fixnum x); cell read_cell_hex(); + + + + // os-* + inline void vmprim_existsp(); + long thread_id(); // os-windows #if defined(WINDOWS) @@ -681,17 +687,17 @@ struct factorvm { void dealloc_segment(segment *block); segment *alloc_segment(cell size); const vm_char *vm_executable_path(); - inline void vmprim_existsp(); const vm_char *default_image_path(); void windows_image_path(vm_char *full_path, vm_char *temp_path, unsigned int length); bool windows_stat(vm_char *path); - + #if defined(WINNT) s64 current_micros(); void c_to_factor_toplevel(cell quot); void open_console(); - // next method here: + // next method here: #endif + #endif };