vm: split up TLS code and add a dummy implementation for a dummy OS known as NetBSD

release
Slava Pestov 2010-03-29 02:23:21 -04:00
parent 8ab0d12e8d
commit 43b2e02534
21 changed files with 134 additions and 85 deletions

View File

@ -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 \

View File

@ -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 \

View 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)

View 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)

View 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

View 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)

View 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

View 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

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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"

28
vm/mvm-none.cpp Normal file
View File

@ -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;
}
}

26
vm/mvm-unix.cpp Normal file
View File

@ -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;
}
}

27
vm/mvm-windows-nt.cpp Normal file
View File

@ -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;
}
}

29
vm/mvm.cpp Normal file
View File

@ -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);
}
}

12
vm/mvm.hpp Normal file
View File

@ -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;
}

View 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()

View 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);

View File

@ -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;

View File

@ -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();
}

View File

@ -715,6 +715,4 @@ struct factor_vm
~factor_vm();
};
extern std::map<THREADHANDLE, factor_vm *> thread_vms;
}