]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: split up TLS code and add a dummy implementation for a dummy OS known as NetBSD
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 29 Mar 2010 06:23:21 +0000 (02:23 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 29 Mar 2010 06:23:21 +0000 (02:23 -0400)
21 files changed:
GNUmakefile
Nmakefile
vm/Config.freebsd
vm/Config.linux
vm/Config.macosx
vm/Config.netbsd
vm/Config.openbsd
vm/Config.windows.nt
vm/factor.cpp
vm/factor.hpp
vm/master.hpp
vm/mvm-none.cpp [new file with mode: 0644]
vm/mvm-unix.cpp [new file with mode: 0644]
vm/mvm-windows-nt.cpp [new file with mode: 0644]
vm/mvm.cpp [new file with mode: 0644]
vm/mvm.hpp [new file with mode: 0644]
vm/os-unix.cpp
vm/os-unix.hpp
vm/os-windows-nt.cpp
vm/os-windows-nt.hpp
vm/vm.hpp

index eac1c696df5b5ecab92c5eb709d48b2c60f79bb7..12ca388f87f3f6ea668899cf4b1cf5990fff8550 100755 (executable)
@@ -52,6 +52,7 @@ ifdef CONFIG
                vm/io.o \
                vm/jit.o \
                vm/math.o \
+               vm/mvm.o \
                vm/nursery_collector.o \
                vm/object_start_map.o \
                vm/objects.o \
index 7349deae23b27727f089c75bdd74060b565342f1..a73a59d0f573f3eb9b05c8f1a5fc507556bbc0e4 100755 (executable)
--- a/Nmakefile
+++ b/Nmakefile
@@ -38,6 +38,8 @@ DLL_OBJS = vm\os-windows-nt.obj \
        vm\io.obj \
        vm\jit.obj \
        vm\math.obj \
+       vm\mvm.obj \
+       vm\mvm-windows-nt.obj \
        vm\nursery_collector.obj \
        vm\object_start_map.obj \
        vm\objects.obj \
index a0dbe228e530a99041057c188da9c5d536041e85..4dc56cfaedc4d19999722dd8644f45e897d88ccb 100644 (file)
@@ -1,4 +1,4 @@
 include vm/Config.unix
-PLAF_DLL_OBJS += vm/os-genunix.o vm/os-freebsd.o
+PLAF_DLL_OBJS += vm/os-genunix.o vm/os-freebsd.o vm/mvm-unix.o
 CFLAGS += -export-dynamic
 LIBS = -L/usr/local/lib/ -lm -lrt $(X11_UI_LIBS)
index 4a859b1216ec1c404a5ee04bd182146669000432..00ff73522a1391610d0a74856b3a4e23e46985d7 100644 (file)
@@ -1,4 +1,4 @@
 include vm/Config.unix
-PLAF_DLL_OBJS += vm/os-genunix.o vm/os-linux.o
+PLAF_DLL_OBJS += vm/os-genunix.o vm/os-linux.o vm/mvm-unix.o
 CFLAGS += -export-dynamic
 LIBS = -ldl -lm -lrt -lpthread $(X11_UI_LIBS)
index 89fe239668bd53f2c1af3b78ff49c05d14cbbcc7..5b9de7f5cf8fb5a45f372df1390b8c5530d9e9fc 100644 (file)
@@ -1,7 +1,7 @@
 include vm/Config.unix
 CFLAGS += -fPIC
 
-PLAF_DLL_OBJS += vm/os-macosx.o vm/mach_signal.o
+PLAF_DLL_OBJS += vm/os-macosx.o vm/mach_signal.o vm/mvm-unix.o
 
 DLL_EXTENSION = .dylib
 SHARED_DLL_EXTENSION = .dylib
index 72a4056c90b4e44c96b9bc66f09a4681f81c7b97..2838f9d4c57d7392341f286485fec48eb7d8cf69 100644 (file)
@@ -1,5 +1,5 @@
 include vm/Config.unix
-PLAF_DLL_OBJS += vm/os-genunix.o vm/os-netbsd.o
+PLAF_DLL_OBJS += vm/os-genunix.o vm/os-netbsd.o vm/mvm-none.o
 CFLAGS += -export-dynamic
 LIBPATH = -L/usr/X11R7/lib -Wl,-rpath,/usr/X11R7/lib -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib
 LIBS = -lm -lrt -lssl -lcrypto $(X11_UI_LIBS)
index c7d2672e6b326209ee1e11ab4ab8e275e206e8ae..6983223b747260e62f1e8235ab5a136ffaa8a280 100644 (file)
@@ -1,5 +1,5 @@
 include vm/Config.unix
-PLAF_DLL_OBJS += vm/os-genunix.o vm/os-openbsd.o
+PLAF_DLL_OBJS += vm/os-genunix.o vm/os-openbsd.o vm/mvm-unix.o
 CC = egcc
 CPP = eg++
 CFLAGS += -export-dynamic -fno-inline-functions
index ffaa899fe1e35cd875d0e7a46ef7f88207de8d57..322649dc0663925a536516a9cab569d8725d9737 100644 (file)
@@ -1,7 +1,7 @@
 LIBS = -lm
 EXE_SUFFIX=
 DLL_SUFFIX=
-PLAF_DLL_OBJS += vm/os-windows-nt.o
+PLAF_DLL_OBJS += vm/os-windows-nt.o vm/mvm-windows-nt.o
 PLAF_EXE_OBJS += vm/resources.o
 PLAF_EXE_OBJS += vm/main-windows-nt.o
 CFLAGS += -mwindows
index c33db440a0ee29e0f177a03c2adf62ab004aaa07..e726ebf6dad6cbbbba8b54cc2a5bd0901eaf8652 100755 (executable)
@@ -3,11 +3,9 @@
 namespace factor
 {
 
-std::map<THREADHANDLE, factor_vm*> thread_vms;
-
 void init_globals()
 {
-       init_platform_globals();
+       init_mvm();
 }
 
 void factor_vm::default_parameters(vm_parameters *p)
@@ -205,11 +203,6 @@ void factor_vm::start_standalone_factor(int argc, vm_char **argv)
        start_factor(&p);
 }
 
-struct startargs {
-       int argc;
-       vm_char **argv;
-};
-
 factor_vm *new_factor_vm()
 {
        factor_vm *newvm = new factor_vm();
@@ -219,28 +212,10 @@ factor_vm *new_factor_vm()
        return newvm;
 }
 
-// arg must be new'ed because we're going to delete it!
-void *start_standalone_factor_thread(void *arg) 
-{
-       factor_vm *newvm = new_factor_vm();
-       startargs *args = (startargs*) arg;
-       int argc = args->argc; vm_char **argv = args->argv;
-       delete args;
-       newvm->start_standalone_factor(argc, argv);
-       return 0;
-}
-
 VM_C_API void start_standalone_factor(int argc, vm_char **argv)
 {
        factor_vm *newvm = new_factor_vm();
        return newvm->start_standalone_factor(argc,argv);
 }
 
-VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv)
-{
-       startargs *args = new startargs;
-       args->argc = argc; args->argv = argv; 
-       return start_thread(start_standalone_factor_thread,args);
-}
-
 }
index cec59bcc5c412f4c85738ba7be5add194e8a25ad..f2dd6af0bf5b62b50edfb4b81eefa71c59fdf053 100755 (executable)
@@ -2,7 +2,7 @@ namespace factor
 {
 
 VM_C_API void init_globals();
+factor_vm *new_factor_vm();
 VM_C_API void start_standalone_factor(int argc, vm_char **argv);
-VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv);
 
 }
index dca3d7473cf9b0405cae7f2d11091860b5c494a2..9879fa607a3cccf8f8ab27d5770fa1f3916b34a6 100755 (executable)
@@ -132,6 +132,7 @@ namespace factor
 #include "jit.hpp"
 #include "quotations.hpp"
 #include "inline_cache.hpp"
+#include "mvm.hpp"
 #include "factor.hpp"
 #include "utilities.hpp"
 
diff --git a/vm/mvm-none.cpp b/vm/mvm-none.cpp
new file mode 100644 (file)
index 0000000..ab1b53a
--- /dev/null
@@ -0,0 +1,28 @@
+#include "master.hpp"
+
+/* Multi-VM threading is not supported on NetBSD due to
+http://gnats.netbsd.org/25563 */
+
+namespace factor
+{
+
+factor_vm *global_vm;
+
+void init_mvm()
+{
+       global_vm = NULL;
+}
+
+void register_vm_with_thread(factor_vm *vm)
+{
+       assert(!global_vm);
+       global_vm = vm;
+}
+
+factor_vm *current_vm()
+{
+       assert(global_vm != NULL);
+       return global_vm;
+}
+
+}
diff --git a/vm/mvm-unix.cpp b/vm/mvm-unix.cpp
new file mode 100644 (file)
index 0000000..110e73f
--- /dev/null
@@ -0,0 +1,26 @@
+#include "master.hpp"
+
+namespace factor
+{
+
+pthread_key_t current_vm_tls_key = 0;
+
+void init_mvm()
+{
+       if(pthread_key_create(&current_vm_tls_key, NULL) != 0)
+               fatal_error("pthread_key_create() failed",0);
+}
+
+void register_vm_with_thread(factor_vm *vm)
+{
+       pthread_setspecific(current_vm_tls_key,vm);
+}
+
+factor_vm *current_vm()
+{
+       factor_vm *vm = (factor_vm*)pthread_getspecific(current_vm_tls_key);
+       assert(vm != NULL);
+       return vm;
+}
+
+}
diff --git a/vm/mvm-windows-nt.cpp b/vm/mvm-windows-nt.cpp
new file mode 100644 (file)
index 0000000..7cb6b82
--- /dev/null
@@ -0,0 +1,27 @@
+#include "master.hpp"
+
+namespace factor
+{
+
+DWORD current_vm_tls_key; 
+
+void init_mvm()
+{
+       if ((current_vm_tls_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
+               fatal_error("TlsAlloc() failed",0);
+}
+
+void register_vm_with_thread(factor_vm *vm)
+{
+       if (!TlsSetValue(current_vm_tls_key, vm))
+               fatal_error("TlsSetValue() failed",0);
+}
+
+factor_vm *current_vm()
+{
+       factor_vm *vm = (factor_vm *)TlsGetValue(current_vm_tls_key);
+       assert(vm != NULL);
+       return vm;
+}
+
+}
diff --git a/vm/mvm.cpp b/vm/mvm.cpp
new file mode 100644 (file)
index 0000000..dda2d66
--- /dev/null
@@ -0,0 +1,29 @@
+#include "master.cpp"
+
+namespace factor
+{
+
+struct startargs {
+       int argc;
+       vm_char **argv;
+};
+
+// arg must be new'ed because we're going to delete it!
+void *start_standalone_factor_thread(void *arg) 
+{
+       factor_vm *newvm = new_factor_vm();
+       startargs *args = (startargs*) arg;
+       int argc = args->argc; vm_char **argv = args->argv;
+       delete args;
+       newvm->start_standalone_factor(argc, argv);
+       return 0;
+}
+
+VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv)
+{
+       startargs *args = new startargs;
+       args->argc = argc; args->argv = argv; 
+       return start_thread(start_standalone_factor_thread,args);
+}
+
+}
diff --git a/vm/mvm.hpp b/vm/mvm.hpp
new file mode 100644 (file)
index 0000000..52430b7
--- /dev/null
@@ -0,0 +1,12 @@
+namespace factor
+{
+
+void init_mvm();
+void register_vm_with_thread(factor_vm *vm);
+factor_vm *current_vm();
+
+VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv);
+
+extern std::map<THREADHANDLE, factor_vm *> thread_vms;
+
+}
index a724007b1a62576fc7ec88168be622503b2eb267..a8898eccab3264423ad1e25de1b8b97f0341f138 100644 (file)
@@ -17,26 +17,6 @@ THREADHANDLE start_thread(void *(*start_routine)(void *),void *args)
        return thread;
 }
 
-pthread_key_t current_vm_tls_key = 0;
-
-void init_platform_globals()
-{
-       if(pthread_key_create(&current_vm_tls_key, NULL) != 0)
-               fatal_error("pthread_key_create() failed",0);
-}
-
-void register_vm_with_thread(factor_vm *vm)
-{
-       pthread_setspecific(current_vm_tls_key,vm);
-}
-
-factor_vm *current_vm()
-{
-       factor_vm *vm = (factor_vm*)pthread_getspecific(current_vm_tls_key);
-       assert(vm != NULL);
-       return vm;
-}
-
 static void *null_dll;
 
 u64 system_micros()
index df6e0b4b3e8e06bcdb38fd3804db3cc9fcb917ec..3673c4e12114b5f09f7b0b78e4fd09d048f2c8c0 100644 (file)
@@ -45,11 +45,6 @@ void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
 u64 system_micros();
 u64 nano_count();
 void sleep_nanos(u64 nsec);
-
-void init_platform_globals();
-
-void register_vm_with_thread(factor_vm *vm);
-factor_vm *current_vm();
 void open_console();
 
 void move_file(const vm_char *path1, const vm_char *path2);
index 54ee78f9773d8a474c4df7ff4006631888afe19d..2d5881252a10872e4ab6b123de9260c8cc0cdfb5 100755 (executable)
@@ -8,27 +8,6 @@ THREADHANDLE start_thread(void *(*start_routine)(void *), void *args)
        return (void *)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, args, 0, 0);
 }
 
-DWORD dwTlsIndex; 
-
-void init_platform_globals()
-{
-       if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
-               fatal_error("TlsAlloc failed - out of indexes",0);
-}
-
-void register_vm_with_thread(factor_vm *vm)
-{
-       if (! TlsSetValue(dwTlsIndex, vm))
-               fatal_error("TlsSetValue failed",0);
-}
-
-factor_vm *current_vm()
-{
-       factor_vm *vm = (factor_vm *)TlsGetValue(dwTlsIndex);
-       assert(vm != NULL);
-       return vm;
-}
-
 u64 system_micros()
 {
        FILETIME t;
index d425a2c2816be453337036d40e1542d62319254b..c5e721c56dd3b915e1dbb2b9626b9e31c6298a35 100755 (executable)
@@ -45,8 +45,4 @@ typedef HANDLE THREADHANDLE;
 THREADHANDLE start_thread(void *(*start_routine)(void *),void *args);
 inline static THREADHANDLE thread_id() { return GetCurrentThread(); }
 
-void init_platform_globals();
-void register_vm_with_thread(factor_vm *vm);
-factor_vm *current_vm();
-
 }
index 4402b64f41723a092942071b7b40b29576e4794d..d304543879713c7b13437247209c06e29634d535 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -715,6 +715,4 @@ struct factor_vm
        ~factor_vm();
 };
 
-extern std::map<THREADHANDLE, factor_vm *> thread_vms;
-
 }