aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-26 08:32:49 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-26 08:32:49 +0000
commitfbf899e0204808fa2a01ade8ca8b69feb1bcc479 (patch)
tree7ccbb6b6733ccb07c28b7df28e3e2a6b604cc731 /thread_pthread.c
parentf8f36a133c610b9ec6aa1f45ffcfc1e74b5e473f (diff)
downloadruby-fbf899e0204808fa2a01ade8ca8b69feb1bcc479.tar.gz
Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038] * vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer. There are many code using `th` to represent execution context (such as cfp, VM stack and so on). To access `ec`, they need to use `th->ec->...` (adding one indirection) so that we need to replace them by passing `ec` instead of `th`. * vm_core.h (GET_EC()): introduced to access current ec. Also remove `ruby_current_thread` global variable. * cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of rb_context_t::thread_value. * cont.c (ec_set_vm_stack): added to update vm_stack explicitly. * cont.c (ec_switch): added to switch ec explicitly. * cont.c (rb_fiber_close): added to terminate fibers explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 83eb721a76..968d7e1f86 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -446,10 +446,8 @@ ruby_thread_set_native(rb_thread_t *th)
static void native_thread_init(rb_thread_t *th);
void
-Init_native_thread(void)
+Init_native_thread(rb_thread_t *th)
{
- rb_thread_t *th = GET_THREAD();
-
pthread_key_create(&ruby_native_thread_key, NULL);
th->thread_id = pthread_self();
fill_thread_id_str(th);
@@ -827,8 +825,8 @@ native_thread_init_stack(rb_thread_t *th)
rb_nativethread_id_t curr = pthread_self();
if (pthread_equal(curr, native_main_thread.id)) {
- th->ec.machine.stack_start = native_main_thread.stack_start;
- th->ec.machine.stack_maxsize = native_main_thread.stack_maxsize;
+ th->ec->machine.stack_start = native_main_thread.stack_start;
+ th->ec->machine.stack_maxsize = native_main_thread.stack_maxsize;
}
else {
#ifdef STACKADDR_AVAILABLE
@@ -837,11 +835,11 @@ native_thread_init_stack(rb_thread_t *th)
if (get_stack(&start, &size) == 0) {
uintptr_t diff = (uintptr_t)start - (uintptr_t)&curr;
- th->ec.machine.stack_start = (VALUE *)&curr;
- th->ec.machine.stack_maxsize = size - diff;
+ th->ec->machine.stack_start = (VALUE *)&curr;
+ th->ec->machine.stack_maxsize = size - diff;
}
#elif defined get_stack_of
- if (!th->ec.machine.stack_maxsize) {
+ if (!th->ec->machine.stack_maxsize) {
native_mutex_lock(&th->interrupt_lock);
native_mutex_unlock(&th->interrupt_lock);
}
@@ -850,9 +848,9 @@ native_thread_init_stack(rb_thread_t *th)
#endif
}
#ifdef __ia64
- th->ec.machine.register_stack_start = native_main_thread.register_stack_start;
- th->ec.machine.stack_maxsize /= 2;
- th->ec.machine.register_stack_maxsize = th->ec.machine.stack_maxsize;
+ th->ec->machine.register_stack_start = native_main_thread.register_stack_start;
+ th->ec->machine.stack_maxsize /= 2;
+ th->ec->machine.register_stack_maxsize = th->ec->machine.stack_maxsize;
#endif
return 0;
}
@@ -880,7 +878,7 @@ thread_start_func_1(void *th_ptr)
native_thread_init(th);
/* run */
#if defined USE_NATIVE_THREAD_INIT
- thread_start_func_2(th, th->ec.machine.stack_start, rb_ia64_bsp());
+ thread_start_func_2(th, th->ec->machine.stack_start, rb_ia64_bsp());
#else
thread_start_func_2(th, &stack_start, rb_ia64_bsp());
#endif
@@ -1002,10 +1000,10 @@ native_thread_create(rb_thread_t *th)
const size_t stack_size = th->vm->default_params.thread_machine_stack_size;
const size_t space = space_size(stack_size);
- th->ec.machine.stack_maxsize = stack_size - space;
+ th->ec->machine.stack_maxsize = stack_size - space;
#ifdef __ia64
- th->ec.machine.stack_maxsize /= 2;
- th->ec.machine.register_stack_maxsize = th->ec.machine.stack_maxsize;
+ th->ec->machine.stack_maxsize /= 2;
+ th->ec->machine.register_stack_maxsize = th->ec->machine.stack_maxsize;
#endif
#ifdef HAVE_PTHREAD_ATTR_INIT
@@ -1028,8 +1026,8 @@ native_thread_create(rb_thread_t *th)
#ifdef get_stack_of
if (!err) {
get_stack_of(th->thread_id,
- &th->ec.machine.stack_start,
- &th->ec.machine.stack_maxsize);
+ &th->ec->machine.stack_start,
+ &th->ec->machine.stack_maxsize);
}
native_mutex_unlock(&th->interrupt_lock);
#endif
@@ -1745,8 +1743,8 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
else
#endif
if (th) {
- size = th->ec.machine.stack_maxsize;
- base = (char *)th->ec.machine.stack_start - STACK_DIR_UPPER(0, size);
+ size = th->ec->machine.stack_maxsize;
+ base = (char *)th->ec->machine.stack_start - STACK_DIR_UPPER(0, size);
}
else {
return 0;