From: Phil Dawes Date: Tue, 25 Aug 2009 17:17:14 +0000 (+0100) Subject: cleaned up code a bit, added multithreaded mode flags X-Git-Tag: 0.97~5502^2~2^2~30 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=ca16daa4b223342c010bfdde6a1f97fd6261b692 cleaned up code a bit, added multithreaded mode flags --- diff --git a/vm/factor.cpp b/vm/factor.cpp index 57bceb9cb7..026453eae3 100755 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -12,9 +12,9 @@ factorvm *lookup_vm(unsigned long threadid) return thread_vms[threadid]; } -void register_vm(unsigned long threadid, factorvm *vm) +void register_vm(unsigned long threadid, factorvm *thevm) { - thread_vms[threadid] = vm; + thread_vms[threadid] = thevm; } diff --git a/vm/main-unix.cpp b/vm/main-unix.cpp index bc605e3cfd..bd1549a38e 100644 --- a/vm/main-unix.cpp +++ b/vm/main-unix.cpp @@ -2,6 +2,11 @@ int main(int argc, char **argv) { - factor::start_standalone_factor(argc,argv); + #ifdef FACTOR_MULTITHREADED + factor::THREADHANDLE thread = factor::start_standalone_factor_in_new_thread(argc,argv); + pthread_join(thread,NULL); + #else + factor::start_standalone_factor(argc,argv); + #endif return 0; } diff --git a/vm/main-windows-nt.cpp b/vm/main-windows-nt.cpp index 4a0fc2ae35..2120717d86 100644 --- a/vm/main-windows-nt.cpp +++ b/vm/main-windows-nt.cpp @@ -16,9 +16,12 @@ int WINAPI WinMain( return 1; } + #ifdef FACTOR_MULTITHREADED + factor::THREADHANDLE thread = factor::start_standalone_factor_in_new_thread(nArgs,szArglist); + WaitForSingleObject(thread, INFINITE); + #else factor::start_standalone_factor(nArgs,szArglist); - //HANDLE thread = factor::start_standalone_factor_in_new_thread(nArgs,szArglist); - //WaitForSingleObject(thread, INFINITE); + #endif LocalFree(szArglist); diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index b37d2beeea..e3e207f641 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -55,6 +55,4 @@ s64 current_micros(); void sleep_micros(cell usec); void open_console(); - -#define SIGNAL_VM_PTR vm } diff --git a/vm/os-windows-nt.hpp b/vm/os-windows-nt.hpp index 68de8ff49e..385553e11e 100755 --- a/vm/os-windows-nt.hpp +++ b/vm/os-windows-nt.hpp @@ -31,6 +31,4 @@ 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/primitives.hpp b/vm/primitives.hpp index 8e6c3b8f51..4be190d4e6 100644 --- a/vm/primitives.hpp +++ b/vm/primitives.hpp @@ -4,15 +4,10 @@ namespace factor #if defined(FACTOR_X86) extern "C" __attribute__ ((regparm (1))) typedef void (*primitive_type)(void *myvm); #define PRIMITIVE(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) - #define PRIMITIVE_GETVM() ((factorvm*)myvm) #else extern "C" typedef void (*primitive_type)(void *myvm); #define PRIMITIVE(name) extern "C" void primitive_##name(void *myvm) - #define PRIMITIVE_GETVM() vm #endif extern const primitive_type primitives[]; -#define PRIMITIVE_OVERFLOW_GETVM() vm -#define VM_PTR vm -#define ASSERTVM() } diff --git a/vm/tagged.hpp b/vm/tagged.hpp index 2bf058212f..13ddf4a047 100755 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -37,13 +37,13 @@ struct tagged explicit tagged(cell tagged) : value_(tagged) { #ifdef FACTOR_DEBUG - untag_check(vm); + untag_check(SIGNAL_VM_PTR); #endif } explicit tagged(TYPE *untagged) : value_(factor::tag(untagged)) { #ifdef FACTOR_DEBUG - untag_check(vm); + untag_check(SIGNAL_VM_PTR); #endif } diff --git a/vm/vm.hpp b/vm/vm.hpp index 65e41881cb..35011171ee 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -677,17 +677,47 @@ struct factorvm { bool windows_stat(vm_char *path); #if defined(WINNT) - void c_to_factor_toplevel(cell quot); void open_console(); // next method here: #endif + #else // UNIX + + stack_frame *uap_stack_pointer(void *uap); #endif }; -extern factorvm *vm; extern factorvm *lookup_vm(unsigned long threadid); extern void register_vm(unsigned long threadid,factorvm *vm); + +#define FACTOR_SINGLE_THREADED + +#ifdef FACTOR_SINGLE_THREADED + extern factorvm *vm; + #define PRIMITIVE_GETVM() vm + #define PRIMITIVE_OVERFLOW_GETVM() vm + #define VM_PTR vm + #define ASSERTVM() + #define SIGNAL_VM_PTR vm +#endif + +#ifdef FACTOR_TESTING_MULTITHREADED + extern factorvm *vm; + #define PRIMITIVE_GETVM() ((factorvm*)myvm) + #define PRIMITIVE_OVERFLOW_GETVM() vm + #define VM_PTR myvm + #define ASSERTVM() assert(vm==myvm) + #define SIGNAL_VM_PTR lookup_vm(thread_id()) +#endif + +#ifdef FACTOR_MULTITHREADED + #define PRIMITIVE_GETVM() ((factorvm*)myvm) + #define PRIMITIVE_OVERFLOW_GETVM() ((factorvm*)myvm) + #define VM_PTR myvm + #define ASSERTVM() + #define SIGNAL_VM_PTR lookup_vm(thread_id()) +#endif + }