summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 05:14:47 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 05:14:47 +0000
commit1ea49760417b17e62a90cce3d736f777cbfd52b7 (patch)
tree24ebdc99ceddd7afb789e39ac025ee42c53ff6fe /thread.c
parente8bd56f5c34689d1211552863359a219ba2fce7e (diff)
* thread_pthread.c (native_set_thread_name): New function to
set thread name visible with ps command on GNU/Linux. Ex. ps -o %c -L * thread.c (thread_start_func_2): Call native_set_thread_name at beginning. (rb_thread_inspect_msg): Extract from rb_thread_inspect. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/thread.c b/thread.c
index 7fbe78eff7..4365c1fa6d 100644
--- a/thread.c
+++ b/thread.c
@@ -571,6 +571,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
TH_PUSH_TAG(th);
if ((state = EXEC_TAG()) == 0) {
SAVE_ROOT_JMPBUF(th, {
+ native_set_thread_name(th);
if (!th->first_func) {
GetProcPtr(th->first_proc, proc);
th->errinfo = Qnil;
@@ -2701,15 +2702,8 @@ rb_thread_safe_level(VALUE thread)
return INT2NUM(th->safe_level);
}
-/*
- * call-seq:
- * thr.inspect -> string
- *
- * Dump the name, id, and status of _thr_ to a string.
- */
-
static VALUE
-rb_thread_inspect(VALUE thread)
+rb_thread_inspect_msg(VALUE thread, int show_enclosure, int show_location, int show_status)
{
VALUE cname = rb_class_path(rb_obj_class(thread));
rb_thread_t *th;
@@ -2718,8 +2712,11 @@ rb_thread_inspect(VALUE thread)
GetThreadPtr(thread, th);
status = thread_status_name(th);
- str = rb_sprintf("#<%"PRIsVALUE":%p", cname, (void *)thread);
- if (!th->first_func && th->first_proc) {
+ if (show_enclosure)
+ str = rb_sprintf("#<%"PRIsVALUE":%p", cname, (void *)thread);
+ else
+ str = rb_str_new(NULL, 0);
+ if (show_location && !th->first_func && th->first_proc) {
long i;
VALUE v, loc = rb_proc_location(th->first_proc);
if (!NIL_P(loc)) {
@@ -2730,12 +2727,28 @@ rb_thread_inspect(VALUE thread)
}
}
}
- rb_str_catf(str, " %s>", status);
+ if (show_status || show_enclosure)
+ rb_str_catf(str, " %s%s",
+ show_status ? status : "",
+ show_enclosure ? ">" : "");
OBJ_INFECT(str, thread);
return str;
}
+/*
+ * call-seq:
+ * thr.inspect -> string
+ *
+ * Dump the name, id, and status of _thr_ to a string.
+ */
+
+static VALUE
+rb_thread_inspect(VALUE thread)
+{
+ return rb_thread_inspect_msg(thread, 1, 1, 1);
+}
+
static VALUE
threadptr_local_aref(rb_thread_t *th, ID id)
{