mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread.c: reset name
* thread.c (rb_thread_setname): allow to reset thread name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c56d9aaabf
commit
62b511d9e6
3 changed files with 21 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Dec 1 23:36:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* thread.c (rb_thread_setname): allow to reset thread name.
|
||||||
|
|
||||||
Tue Dec 1 23:14:04 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Dec 1 23:14:04 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* thread.c (rb_thread_setname): check the argument if valid
|
* thread.c (rb_thread_setname): check the argument if valid
|
||||||
|
|
|
@ -1050,9 +1050,14 @@ q.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_thread_name
|
def test_thread_name
|
||||||
t = Thread.start { sleep }
|
t = Thread.start {}
|
||||||
|
assert_nil t.name
|
||||||
|
s = t.inspect
|
||||||
t.name = 'foo'
|
t.name = 'foo'
|
||||||
assert_equal 'foo', t.name
|
assert_equal 'foo', t.name
|
||||||
|
t.name = nil
|
||||||
|
assert_nil t.name
|
||||||
|
assert_equal s, t.inspect
|
||||||
ensure
|
ensure
|
||||||
t.kill
|
t.kill
|
||||||
t.join
|
t.join
|
||||||
|
@ -1070,7 +1075,7 @@ q.pop
|
||||||
def test_thread_invalid_object
|
def test_thread_invalid_object
|
||||||
bug11756 = '[ruby-core:71774] [Bug #11756]'
|
bug11756 = '[ruby-core:71774] [Bug #11756]'
|
||||||
t = Thread.start {}
|
t = Thread.start {}
|
||||||
assert_raise(TypeError, bug11756) {t.name = nil}
|
assert_raise(TypeError, bug11756) {t.name = []}
|
||||||
ensure
|
ensure
|
||||||
t.kill
|
t.kill
|
||||||
t.join
|
t.join
|
||||||
|
|
13
thread.c
13
thread.c
|
@ -2774,18 +2774,23 @@ rb_thread_getname(VALUE thread)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_thread_setname(VALUE thread, VALUE name)
|
rb_thread_setname(VALUE thread, VALUE name)
|
||||||
{
|
{
|
||||||
|
const char *s = "";
|
||||||
rb_thread_t *th;
|
rb_thread_t *th;
|
||||||
GetThreadPtr(thread, th);
|
GetThreadPtr(thread, th);
|
||||||
|
if (!NIL_P(name)) {
|
||||||
StringValueCStr(name);
|
StringValueCStr(name);
|
||||||
th->name = rb_str_new_frozen(name);
|
name = rb_str_new_frozen(name);
|
||||||
|
s = RSTRING_PTR(name);
|
||||||
|
}
|
||||||
|
th->name = name;
|
||||||
#if defined(HAVE_PTHREAD_SETNAME_NP)
|
#if defined(HAVE_PTHREAD_SETNAME_NP)
|
||||||
# if defined(__linux__)
|
# if defined(__linux__)
|
||||||
pthread_setname_np(th->thread_id, RSTRING_PTR(name));
|
pthread_setname_np(th->thread_id, s);
|
||||||
# elif defined(__NetBSD__)
|
# elif defined(__NetBSD__)
|
||||||
pthread_setname_np(th->thread_id, RSTRING_PTR(name), "%s");
|
pthread_setname_np(th->thread_id, s, "%s");
|
||||||
# endif
|
# endif
|
||||||
#elif defined(HAVE_PTHREAD_SET_NAME_NP) /* FreeBSD */
|
#elif defined(HAVE_PTHREAD_SET_NAME_NP) /* FreeBSD */
|
||||||
pthread_set_name_np(th->thread_id, RSTRING_PTR(name));
|
pthread_set_name_np(th->thread_id, s);
|
||||||
#endif
|
#endif
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue