VM: a bunch of methods on factor_vm that can be converted into free

functions

I think that makes it easier to see whats going on than having
everything added to factor_vm
db4
Björn Lindqvist 2015-08-03 23:06:02 +02:00
parent ae725b737a
commit 73956db33a
5 changed files with 23 additions and 20 deletions

View File

@ -4,4 +4,13 @@ VM_C_API void init_globals();
factor_vm* new_factor_vm(); factor_vm* new_factor_vm();
VM_C_API void start_standalone_factor(int argc, vm_char** argv); VM_C_API void start_standalone_factor(int argc, vm_char** argv);
// os-*
void open_console();
void close_console();
void lock_console();
void unlock_console();
void ignore_ctrl_c();
void handle_ctrl_c();
} }

View File

@ -455,7 +455,7 @@ void* stdin_loop(void* arg) {
return NULL; return NULL;
} }
void factor_vm::open_console() { void open_console() {
FACTOR_ASSERT(!stdin_thread_initialized_p); FACTOR_ASSERT(!stdin_thread_initialized_p);
safe_pipe(&control_read, &control_write); safe_pipe(&control_read, &control_write);
safe_pipe(&size_read, &size_write); safe_pipe(&size_read, &size_write);
@ -468,14 +468,14 @@ void factor_vm::open_console() {
/* This method is used to kill the stdin_loop before exiting from factor. /* This method is used to kill the stdin_loop before exiting from factor.
A Nvidia driver bug on Linux is the reason this has to be done, see: A Nvidia driver bug on Linux is the reason this has to be done, see:
http://www.nvnews.net/vbulletin/showthread.php?t=164619 */ http://www.nvnews.net/vbulletin/showthread.php?t=164619 */
void factor_vm::close_console() { void close_console() {
if (stdin_thread_initialized_p) { if (stdin_thread_initialized_p) {
pthread_cancel(stdin_thread); pthread_cancel(stdin_thread);
pthread_join(stdin_thread, 0); pthread_join(stdin_thread, 0);
} }
} }
void factor_vm::lock_console() { void lock_console() {
FACTOR_ASSERT(stdin_thread_initialized_p); FACTOR_ASSERT(stdin_thread_initialized_p);
/* Lock the stdin_mutex and send the stdin_loop thread a signal to interrupt /* Lock the stdin_mutex and send the stdin_loop thread a signal to interrupt
any read() it has in progress. When the stdin loop iterates again, it will any read() it has in progress. When the stdin loop iterates again, it will
@ -484,19 +484,19 @@ void factor_vm::lock_console() {
pthread_kill(stdin_thread, SIGUSR2); pthread_kill(stdin_thread, SIGUSR2);
} }
void factor_vm::unlock_console() { void unlock_console() {
FACTOR_ASSERT(stdin_thread_initialized_p); FACTOR_ASSERT(stdin_thread_initialized_p);
pthread_mutex_unlock(&stdin_mutex); pthread_mutex_unlock(&stdin_mutex);
} }
void factor_vm::ignore_ctrl_c() { void ignore_ctrl_c() {
sig_t ret; sig_t ret;
do { do {
ret = signal(SIGINT, SIG_DFL); ret = signal(SIGINT, SIG_DFL);
} while (ret == SIG_ERR && errno == EINTR); } while (ret == SIG_ERR && errno == EINTR);
} }
void factor_vm::handle_ctrl_c() { void handle_ctrl_c() {
struct sigaction fep_sigaction; struct sigaction fep_sigaction;
init_sigaction_with_handler(&fep_sigaction, fep_signal_handler); init_sigaction_with_handler(&fep_sigaction, fep_signal_handler);
sigaction_safe(SIGINT, &fep_sigaction, NULL); sigaction_safe(SIGINT, &fep_sigaction, NULL);
@ -508,7 +508,7 @@ void abort() {
ret = signal(SIGABRT, SIG_DFL); ret = signal(SIGABRT, SIG_DFL);
} while (ret == SIG_ERR && errno == EINTR); } while (ret == SIG_ERR && errno == EINTR);
factor_vm::close_console(); close_console();
::abort(); ::abort();
} }

View File

@ -295,21 +295,21 @@ static BOOL WINAPI ctrl_handler(DWORD dwCtrlType) {
} }
} }
void factor_vm::open_console() { handle_ctrl_c(); } void open_console() { handle_ctrl_c(); }
void factor_vm::ignore_ctrl_c() { void ignore_ctrl_c() {
SetConsoleCtrlHandler(factor::ctrl_handler, FALSE); SetConsoleCtrlHandler(factor::ctrl_handler, FALSE);
} }
void factor_vm::handle_ctrl_c() { void handle_ctrl_c() {
SetConsoleCtrlHandler(factor::ctrl_handler, TRUE); SetConsoleCtrlHandler(factor::ctrl_handler, TRUE);
} }
void factor_vm::lock_console() {} void lock_console() {}
void factor_vm::unlock_console() {} void unlock_console() {}
void factor_vm::close_console() {} void close_console() {}
void factor_vm::sampler_thread_loop() { void factor_vm::sampler_thread_loop() {
LARGE_INTEGER counter, new_counter, units_per_second; LARGE_INTEGER counter, new_counter, units_per_second;

View File

@ -5,7 +5,7 @@ namespace factor {
void factor_vm::primitive_exit() { exit((int)to_fixnum(ctx->pop())); } void factor_vm::primitive_exit() { exit((int)to_fixnum(ctx->pop())); }
void exit(int status) { void exit(int status) {
factor_vm::close_console(); close_console();
::exit(status); ::exit(status);
} }

View File

@ -737,12 +737,6 @@ struct factor_vm {
void init_signals(); void init_signals();
void start_sampling_profiler_timer(); void start_sampling_profiler_timer();
void end_sampling_profiler_timer(); void end_sampling_profiler_timer();
static void open_console();
static void close_console();
static void lock_console();
static void unlock_console();
static void ignore_ctrl_c();
static void handle_ctrl_c();
// os-windows // os-windows
#if defined(WINDOWS) #if defined(WINDOWS)