vm: close_console before exiting anywhere
Add a factor_vm::exit function that does close_console() before ::exit-ingdb4
parent
db19efe1b3
commit
3fc82282f7
|
@ -9,7 +9,7 @@ static inline void fa_diddly_atal_error()
|
|||
{
|
||||
printf("fatal_error in fatal_error!\n");
|
||||
breakpoint();
|
||||
exit(86);
|
||||
::_exit(86);
|
||||
}
|
||||
|
||||
void fatal_error(const char *msg, cell tagged)
|
||||
|
@ -38,7 +38,7 @@ void out_of_memory()
|
|||
{
|
||||
std::cout << "Out of memory\n\n";
|
||||
current_vm()->dump_generations();
|
||||
exit(1);
|
||||
abort();
|
||||
}
|
||||
|
||||
void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2)
|
||||
|
|
|
@ -380,6 +380,7 @@ extern "C" {
|
|||
int size_read;
|
||||
int size_write;
|
||||
|
||||
bool stdin_thread_initialized_p = false;
|
||||
THREADHANDLE stdin_thread;
|
||||
pthread_mutex_t stdin_mutex;
|
||||
}
|
||||
|
@ -489,10 +490,12 @@ void *stdin_loop(void *arg)
|
|||
|
||||
void factor_vm::open_console()
|
||||
{
|
||||
assert(!stdin_thread_initialized_p);
|
||||
safe_pipe(&control_read,&control_write);
|
||||
safe_pipe(&size_read,&size_write);
|
||||
safe_pipe(&stdin_read,&stdin_write);
|
||||
stdin_thread = start_thread(stdin_loop,NULL);
|
||||
stdin_thread_initialized_p = true;
|
||||
pthread_mutex_init(&stdin_mutex, NULL);
|
||||
}
|
||||
|
||||
|
@ -501,12 +504,13 @@ void factor_vm::open_console()
|
|||
// http://www.nvnews.net/vbulletin/showthread.php?t=164619
|
||||
void factor_vm::close_console()
|
||||
{
|
||||
pthread_mutex_lock(&stdin_mutex);
|
||||
pthread_kill(stdin_thread, SIGTERM);
|
||||
if (stdin_thread_initialized_p)
|
||||
pthread_kill(stdin_thread, SIGTERM);
|
||||
}
|
||||
|
||||
void factor_vm::lock_console()
|
||||
{
|
||||
assert(stdin_thread_initialized_p);
|
||||
// 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
|
||||
// try to lock the same mutex and wait until unlock_console() is called.
|
||||
|
@ -516,6 +520,7 @@ void factor_vm::lock_console()
|
|||
|
||||
void factor_vm::unlock_console()
|
||||
{
|
||||
assert(stdin_thread_initialized_p);
|
||||
pthread_mutex_unlock(&stdin_mutex);
|
||||
}
|
||||
|
||||
|
@ -528,6 +533,7 @@ void factor_vm::abort()
|
|||
}
|
||||
while(ret == SIG_ERR && errno == EINTR);
|
||||
|
||||
close_console();
|
||||
::abort();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,15 @@ namespace factor
|
|||
|
||||
void factor_vm::primitive_exit()
|
||||
{
|
||||
close_console();
|
||||
exit((int)to_fixnum(ctx->pop()));
|
||||
}
|
||||
|
||||
void factor_vm::exit(int status)
|
||||
{
|
||||
close_console();
|
||||
::exit(status);
|
||||
}
|
||||
|
||||
void factor_vm::primitive_nano_count()
|
||||
{
|
||||
u64 nanos = nano_count();
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace factor
|
|||
|
||||
factor_vm::factor_vm(THREADHANDLE thread) :
|
||||
nursery(0,0),
|
||||
thread(thread),
|
||||
faulting_p(false),
|
||||
thread(thread),
|
||||
callback_id(0),
|
||||
c_to_factor_func(NULL),
|
||||
sampling_profiler_p(false),
|
||||
|
@ -22,7 +23,6 @@ factor_vm::factor_vm(THREADHANDLE thread) :
|
|||
full_output(false),
|
||||
last_nano_count(0),
|
||||
signal_callstack_seg(NULL),
|
||||
faulting_p(false),
|
||||
safepoint()
|
||||
{
|
||||
primitive_reset_dispatch_stats();
|
||||
|
|
10
vm/vm.hpp
10
vm/vm.hpp
|
@ -189,6 +189,7 @@ struct factor_vm
|
|||
void primitive_nano_count();
|
||||
void primitive_sleep();
|
||||
void primitive_set_slot();
|
||||
static void exit(int status);
|
||||
|
||||
// objects
|
||||
void primitive_special_object();
|
||||
|
@ -731,11 +732,12 @@ struct factor_vm
|
|||
void init_signals();
|
||||
void start_sampling_profiler_timer();
|
||||
void end_sampling_profiler_timer();
|
||||
void open_console();
|
||||
void close_console();
|
||||
void lock_console();
|
||||
void unlock_console();
|
||||
static void open_console();
|
||||
static void close_console();
|
||||
static void lock_console();
|
||||
static void unlock_console();
|
||||
static void abort();
|
||||
static void exit();
|
||||
|
||||
// os-windows
|
||||
#if defined(WINDOWS)
|
||||
|
|
Loading…
Reference in New Issue