Skip to content

Commit

Permalink
Fixed halt race.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Apr 18, 2015
1 parent ed2393f commit 95c00d3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
4 changes: 0 additions & 4 deletions vm/drivers/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,5 @@ int main(int argc, char** argv) {
}
}

#ifdef ENABLE_LLVM
llvm::llvm_shutdown();
#endif

return exit_code;
}
27 changes: 22 additions & 5 deletions vm/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ namespace rubinius {
#endif
#endif

halt_lock_.init();

String::init_hash();

VM::init_stack_size();
Expand Down Expand Up @@ -164,6 +166,8 @@ namespace rubinius {
if(state->shared().llvm_state) {
state->shared().llvm_state->stop(state);
}

llvm::llvm_shutdown();
#endif
}

Expand Down Expand Up @@ -521,9 +525,24 @@ namespace rubinius {
}

void Environment::after_exec(STATE) {
halt_lock_.init();
create_fsapi(state);
}

void Environment::after_fork_child(STATE) {
halt_lock_.init();

set_pid();
set_fsapi_path();

stop_logging(state);
start_logging(state);
}

void Environment::after_fork_exec_child(STATE) {
halt_lock_.init();
}

void Environment::create_fsapi(STATE) {
if(mkdir(shared->fsapi_path.c_str(), shared->config.system_fsapi_access) < 0) {
utilities::logger::error("%s: unable to create FSAPI path", strerror(errno));
Expand All @@ -543,14 +562,12 @@ namespace rubinius {

void Environment::halt_and_exit(STATE) {
halt(state);
int code = exit_code(state);
#ifdef ENABLE_LLVM
llvm::llvm_shutdown();
#endif
exit(code);
exit(exit_code(state));
}

void Environment::halt(STATE) {
utilities::thread::Mutex::LockGuard guard(halt_lock_);

state->shared().tool_broker()->shutdown(state);

if(ImmixMarker* im = state->memory()->immix_marker()) {
Expand Down
4 changes: 4 additions & 0 deletions vm/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace rubinius {

std::string system_prefix_;

utilities::thread::Mutex halt_lock_;

public:
SharedState* shared;
VM* root_vm;
Expand Down Expand Up @@ -111,6 +113,8 @@ namespace rubinius {

void before_exec(STATE);
void after_exec(STATE);
void after_fork_child(STATE);
void after_fork_exec_child(STATE);

void halt(STATE);
void halt_and_exit(STATE);
Expand Down
2 changes: 2 additions & 0 deletions vm/internal_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ namespace rubinius {
(*i)->after_fork_exec_child(state);
}

state->shared().env()->after_fork_exec_child(state);
fork_exec_in_progress_ = false;
}

Expand Down Expand Up @@ -228,6 +229,7 @@ namespace rubinius {
(*i)->after_fork_child(state);
}

state->shared().env()->after_fork_child(state);
fork_in_progress_ = false;
}

Expand Down
6 changes: 0 additions & 6 deletions vm/shared_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ namespace rubinius {
capi_constant_lock_.init();
internal_threads_->init();

env_->set_pid();
env_->set_fsapi_path();

env_->stop_logging(state);
env_->start_logging(state);

om->after_fork_child(state);

state->vm()->set_run_state(ManagedThread::eIndependent);
Expand Down

0 comments on commit 95c00d3

Please sign in to comment.