From 78bb06143654fa0010e9139dade010c8bdc779ef Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 9 Oct 2001 08:19:46 +0000 Subject: * eval.c (thread_status_name): separated from rb_thread_inspect(). return string expression for thread status. * eval.c (rb_thread_status, rb_thread_inspect): use thread_status_name(). * eval.c (rb_thread_priority_set): return the priority not but self. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ eval.c | 38 +++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1dfa1b99..64f47d060 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Oct 9 17:08:00 2001 Nobuyoshi Nakada + + * eval.c (thread_status_name): separated from + rb_thread_inspect(). return string expression for thread status. + + * eval.c (rb_thread_status, rb_thread_inspect): use + thread_status_name(). + + * eval.c (rb_thread_priority_set): return the priority not but + self. + Fri Oct 5 15:19:46 2001 Yukihiro Matsumoto * marshal.c (w_unique): should not dump anonymous class. diff --git a/eval.c b/eval.c index d7608bf22..1023bbbc6 100644 --- a/eval.c +++ b/eval.c @@ -7110,6 +7110,24 @@ struct thread { #define FOREACH_THREAD(x) FOREACH_THREAD_FROM(curr_thread,x) #define END_FOREACH(x) END_FOREACH_FROM(curr_thread,x) +static const char * +thread_status_name(status) + enum thread_status status; +{ + switch (status) { + case THREAD_RUNNABLE: + return "run"; + case THREAD_STOPPED: + return "sleep"; + case THREAD_TO_KILL: + return "aborting"; + case THREAD_KILLED: + return "dead"; + default: + return "unknown"; + } +} + /* $SAFE accessor */ void rb_set_safe_level(level) @@ -8134,7 +8152,7 @@ rb_thread_priority_set(thread, prio) th->priority = NUM2INT(prio); rb_thread_schedule(); - return thread; + return prio; } static VALUE @@ -8486,9 +8504,7 @@ rb_thread_status(thread) return Qfalse; } - if (th->status == THREAD_STOPPED) - return rb_str_new2("sleep"); - return rb_str_new2("run"); + return rb_str_new2(thread_status_name(th->status)); } static VALUE @@ -8777,21 +8793,9 @@ rb_thread_inspect(thread) { char *cname = rb_class2name(CLASS_OF(thread)); rb_thread_t th = rb_thread_check(thread); - char *status; + const char *status = thread_status_name(th->status); VALUE str; - switch (th->status) { - case THREAD_RUNNABLE: - status = "run"; break; - case THREAD_STOPPED: - status = "sleep"; break; - case THREAD_TO_KILL: - status = "aborting"; break; - case THREAD_KILLED: - status = "dead"; break; - default: - status = "unknown"; break; - } str = rb_str_new(0, strlen(cname)+7+16+9+1); /* 7:tags 16:addr 9:status 1:nul */ sprintf(RSTRING(str)->ptr, "#<%s:0x%lx %s>", cname, thread, status); RSTRING(str)->len = strlen(RSTRING(str)->ptr); -- cgit