summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-08 05:01:23 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-08 05:01:23 (GMT)
commit26081169e0a227a6ccf477c7fade17b90f266e23 (patch)
treec27e9109ef640c0de230c50c698df4a1fe1a2608 /thread_pthread.c
parent96af6823c1b49a41e873fb4d9ffa16dfce7ffdd9 (diff)
separate Thread type (func or proc) explicitly.
* vm_core.h (rb_thread_struct): introduce new fields `invoke_type` and `invoke_arg`. There are two types threads: invoking proc (normal Ruby thread created by `Thread.new do ... end`) and invoking func, created by C-API. `invoke_type` shows the types. * thread.c (thread_do_start): copy `invoke_arg.proc.args` contents from Array to ALLOCA stack memory if args length is enough small (<8). We don't need to keep Array and don't need to cancel using transient heap. * vm.c (thread_mark): For func invoking threads, they can pass (void *) parameter (rb_thread_t::invoke_arg::func::arg). However, a rubyspec test (thread_spec.c) passes an Array object and it expect to mark it. Clealy it is out of scope (misuse of `rb_thread_create` C-API). However, I'm not sure someone else has such kind of misunderstanding. So now we mark conservatively this (void *) arg with rb_gc_mark_maybe. This misuse is found by this error log. http://ci.rvm.jp/results/trunk-theap-asserts@silicon-docker/1448164 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 22ca4c2..aa5fe66 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1613,36 +1613,36 @@ setup_communication_pipe_internal(int pipes[2])
# define SET_CURRENT_THREAD_NAME(name) prctl(PR_SET_NAME, name)
#endif
+static VALUE threadptr_invoke_proc_location(rb_thread_t *th);
+
static void
native_set_thread_name(rb_thread_t *th)
{
#ifdef SET_CURRENT_THREAD_NAME
- if (!th->first_func && th->first_proc) {
- VALUE loc;
- if (!NIL_P(loc = th->name)) {
- SET_CURRENT_THREAD_NAME(RSTRING_PTR(loc));
- }
- else if (!NIL_P(loc = rb_proc_location(th->first_proc))) {
- char *name, *p;
- char buf[16];
- size_t len;
- int n;
-
- name = RSTRING_PTR(RARRAY_AREF(loc, 0));
- p = strrchr(name, '/'); /* show only the basename of the path. */
- if (p && p[1])
- name = p + 1;
-
- n = snprintf(buf, sizeof(buf), "%s:%d", name, NUM2INT(RARRAY_AREF(loc, 1)));
- rb_gc_force_recycle(loc); /* acts as a GC guard, too */
-
- len = (size_t)n;
- if (len >= sizeof(buf)) {
- buf[sizeof(buf)-2] = '*';
- buf[sizeof(buf)-1] = '\0';
- }
- SET_CURRENT_THREAD_NAME(buf);
- }
+ VALUE loc;
+ if (!NIL_P(loc = th->name)) {
+ SET_CURRENT_THREAD_NAME(RSTRING_PTR(loc));
+ }
+ else if ((loc = threadptr_invoke_proc_location(th)) != Qnil) {
+ char *name, *p;
+ char buf[16];
+ size_t len;
+ int n;
+
+ name = RSTRING_PTR(RARRAY_AREF(loc, 0));
+ p = strrchr(name, '/'); /* show only the basename of the path. */
+ if (p && p[1])
+ name = p + 1;
+
+ n = snprintf(buf, sizeof(buf), "%s:%d", name, NUM2INT(RARRAY_AREF(loc, 1)));
+ rb_gc_force_recycle(loc); /* acts as a GC guard, too */
+
+ len = (size_t)n;
+ if (len >= sizeof(buf)) {
+ buf[sizeof(buf)-2] = '*';
+ buf[sizeof(buf)-1] = '\0';
+ }
+ SET_CURRENT_THREAD_NAME(buf);
}
#endif
}