Permalink
Browse files

Store the thread name in the managed thread

This makes debugging somewhat easier when we deadlock because we can see
which thread is actually problematic if we call methods on other running
threads such as getting backtraces.
  • Loading branch information...
1 parent 59ab694 commit 297239a368049b7436497e5d0e906406a0b55d9c @dbussink dbussink committed Oct 4, 2012
Showing with 15 additions and 18 deletions.
  1. +1 −1 vm/agent_components.cpp
  2. +2 −3 vm/builtin/thread.cpp
  3. +3 −1 vm/gc/managed.cpp
  4. +4 −4 vm/gc/managed.hpp
  5. +1 −3 vm/llvm/state.cpp
  6. +3 −5 vm/vm.cpp
  7. +1 −1 vm/vm.hpp
View
@@ -347,7 +347,7 @@ namespace agent {
} else {
output.e().write_tuple(2);
output.e().write_atom("system");
- output.e().write_binary(thr->name());
+ output.e().write_binary(thr->name().c_str());
}
}
View
@@ -208,11 +208,10 @@ namespace rubinius {
int calculate_stack = 0;
NativeMethod::init_thread(state);
- VM::set_current(vm);
-
std::ostringstream tn;
tn << "rbx.ruby." << vm->thread_id();
- utilities::thread::Thread::set_os_name(tn.str().c_str());
+
+ VM::set_current(vm, tn.str());
state->set_call_frame(0);
View
@@ -19,8 +19,10 @@ namespace rubinius {
return _current_thread.get();
}
- void ManagedThread::set_current(ManagedThread* th) {
+ void ManagedThread::set_current(ManagedThread* th, std::string name) {
th->os_thread_ = pthread_self();
_current_thread.set(th);
+ th->name_ = name;
+ utilities::thread::Thread::set_os_name(name.c_str());
}
}
View
@@ -34,7 +34,7 @@ namespace rubinius {
SharedState& shared_;
Roots roots_;
Kind kind_;
- const char* name_;
+ std::string name_;
VariableRootBuffers variable_root_buffers_;
RootBuffers root_buffers_;
RunState run_state_;
@@ -85,11 +85,11 @@ namespace rubinius {
return 0;
}
- const char* name() {
+ std::string name() {
return name_;
}
- void set_name(const char* name) {
+ void set_name(std::string name) {
name_ = name;
}
@@ -111,7 +111,7 @@ namespace rubinius {
public:
static ManagedThread* current();
- static void set_current(ManagedThread* vm);
+ static void set_current(ManagedThread* vm, std::string name);
};
}
View
@@ -221,9 +221,7 @@ namespace rubinius {
}
virtual void perform() {
- set_name("rbx.jit");
-
- ManagedThread::set_current(ls_);
+ ManagedThread::set_current(ls_, "rbx.jit");
#ifndef RBX_WINDOWS
sigset_t set;
View
@@ -113,8 +113,6 @@ namespace rubinius {
void VM::initialize_as_root() {
- utilities::thread::Thread::set_os_name("rbx.ruby.main");
-
om = new ObjectMemory(this, shared.config);
shared.om = om;
@@ -142,7 +140,7 @@ namespace rubinius {
thread.set(Thread::create(&state, this, G(thread), 0, true), &globals().roots);
thread->sleep(&state, cFalse);
- VM::set_current(this);
+ VM::set_current(this, "rbx.ruby.main");
}
void VM::initialize_config() {
@@ -178,8 +176,8 @@ namespace rubinius {
/**
* Sets this VM instance as the current VM on this pthread.
*/
- void VM::set_current(VM* vm) {
- ManagedThread::set_current(vm);
+ void VM::set_current(VM* vm, std::string name) {
+ ManagedThread::set_current(vm, name);
}
Object* VM::new_object_typed(Class* cls, size_t size, object_type type) {
View
@@ -295,7 +295,7 @@ namespace rubinius {
static void init_stack_size();
static VM* current();
- static void set_current(VM* vm);
+ static void set_current(VM* vm, std::string name);
static void discard(STATE, VM*);

0 comments on commit 297239a

Please sign in to comment.