From: Phil Dawes Date: Tue, 25 Aug 2009 07:55:18 +0000 (+0100) Subject: moved the thread stuff around a bit X-Git-Tag: 0.97~5502^2~2^2~32 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=3c139593c5b248fcf159a20500a9223fc55aa644 moved the thread stuff around a bit --- diff --git a/vm/factor.cpp b/vm/factor.cpp index a241ccf86b..57bceb9cb7 100755 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -7,12 +7,12 @@ factorvm *vm; unordered_map thread_vms; -factorvm *lookup_vm(long threadid) +factorvm *lookup_vm(unsigned long threadid) { return thread_vms[threadid]; } -void register_vm(long threadid, factorvm *vm) +void register_vm(unsigned long threadid, factorvm *vm) { thread_vms[threadid] = vm; } @@ -243,7 +243,7 @@ VM_C_API void start_standalone_factor(int argc, vm_char **argv) return newvm->start_standalone_factor(argc,argv); } -VM_C_API void *start_standalone_factor_in_new_thread(int argc, vm_char **argv) +VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv) { startargs *args = new startargs; // leaks startargs structure args->argc = argc; args->argv = argv; diff --git a/vm/factor.hpp b/vm/factor.hpp index b824758c8a..46662072b5 100644 --- a/vm/factor.hpp +++ b/vm/factor.hpp @@ -2,5 +2,5 @@ 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); +VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv); } diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index ed007398a3..7f4b070c60 100644 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -3,7 +3,7 @@ namespace factor { -void *start_thread(void *(*start_routine)(void *),void *args) +THREADHANDLE start_thread(void *(*start_routine)(void *),void *args) { pthread_attr_t attr; pthread_t thread; @@ -14,9 +14,14 @@ void *start_thread(void *(*start_routine)(void *),void *args) if (pthread_create (&thread, &attr, start_routine, args) != 0) fatal_error("pthread_create() failed",0); pthread_attr_destroy (&attr); - return (void*)thread; + return thread; } +unsigned long thread_id(){ + return pthread_self(); +} + + static void *null_dll; s64 current_micros() @@ -56,9 +61,6 @@ void factorvm::ffi_dlclose(dll *dll) } -cell factorvm::thread_id(){ - return pthread_self(); -} inline void factorvm::vmprim_existsp() diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index 60beb88233..b37d2beeea 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -42,12 +42,10 @@ typedef char symbol_char; #define print_native_string(string) print_string(string) -void *start_thread(void *(*start_routine)(void *),void *args); +typedef pthread_t THREADHANDLE; -void init_ffi(); -void ffi_dlopen(dll *dll); -void *ffi_dlsym(dll *dll, symbol_char *symbol); -void ffi_dlclose(dll *dll); +THREADHANDLE start_thread(void *(*start_routine)(void *),void *args); +unsigned long thread_id(); void unix_init_signals(); void signal_handler(int signal, siginfo_t* siginfo, void* uap); diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index 630782a946..fbaadaaba7 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -3,16 +3,16 @@ namespace factor { -void *start_thread(void *(*start_routine)(void *),void *args){ - return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, args, 0, 0); +THREADHANDLE start_thread(void *(*start_routine)(void *),void *args){ + return (void*) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, args, 0, 0); } -cell factorvm::thread_id(){ +unsigned long thread_id(){ return GetCurrentThreadId(); } -s64 factorvm::current_micros() +s64 current_micros() { FILETIME t; GetSystemTimeAsFileTime(&t); diff --git a/vm/os-windows-nt.hpp b/vm/os-windows-nt.hpp index e5c5adadf1..68de8ff49e 100755 --- a/vm/os-windows-nt.hpp +++ b/vm/os-windows-nt.hpp @@ -26,7 +26,10 @@ FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe); #define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4 #define STATUS_FLOAT_MULTIPLE_TRAPS 0xC00002B5 -void *start_thread(void *(*start_routine)(void *),void *args); +typedef HANDLE THREADHANDLE; + +THREADHANDLE start_thread(void *(*start_routine)(void *),void *args); +unsigned long thread_id(); #define SIGNAL_VM_PTR lookup_vm(GetCurrentThreadId()) diff --git a/vm/vm.hpp b/vm/vm.hpp index 9af73e4c7e..76cf8c4e53 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -659,7 +659,6 @@ struct factorvm { // os-* inline void vmprim_existsp(); - cell thread_id(); void init_ffi(); void ffi_dlopen(dll *dll); void *ffi_dlsym(dll *dll, symbol_char *symbol); @@ -677,7 +676,6 @@ struct factorvm { 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: @@ -689,6 +687,6 @@ struct factorvm { extern factorvm *vm; -extern factorvm *lookup_vm(long threadid); -extern void register_vm(long threadid,factorvm *vm); +extern factorvm *lookup_vm(unsigned long threadid); +extern void register_vm(unsigned long threadid,factorvm *vm); }