* vm_core.h (rb_thread_t): move storages to rb_execution_context_t.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-06-28 02:50:56 +00:00
Родитель b3f38b57e7
Коммит d98afe3ae2
5 изменённых файлов: 66 добавлений и 60 удалений

30
cont.c
Просмотреть файл

@ -319,8 +319,8 @@ fiber_free(void *ptr)
rb_fiber_t *fib = ptr;
RUBY_FREE_ENTER("fiber");
if (fib->cont.type != ROOT_FIBER_CONTEXT &&
fib->cont.saved_thread.local_storage) {
st_free_table(fib->cont.saved_thread.local_storage);
fib->cont.saved_thread.ec.local_storage) {
st_free_table(fib->cont.saved_thread.ec.local_storage);
}
cont_free(&fib->cont);
@ -335,8 +335,8 @@ fiber_memsize(const void *ptr)
size = sizeof(*fib);
if (fib->cont.type != ROOT_FIBER_CONTEXT &&
fib->cont.saved_thread.local_storage != NULL) {
size += st_memsize(fib->cont.saved_thread.local_storage);
fib->cont.saved_thread.ec.local_storage != NULL) {
size += st_memsize(fib->cont.saved_thread.ec.local_storage);
}
size += cont_memsize(&fib->cont);
return size;
@ -411,7 +411,6 @@ cont_save_thread(rb_context_t *cont, rb_thread_t *th)
/* save thread context */
sth->ec = th->ec;
sth->local_storage = th->local_storage;
VM_ASSERT(th->status == THREAD_RUNNABLE);
sth->errinfo = th->errinfo;
sth->first_proc = th->first_proc;
@ -439,9 +438,9 @@ cont_init(rb_context_t *cont, rb_thread_t *th)
cont->saved_thread.self = th->self;
cont->saved_thread.machine.stack_maxsize = th->machine.stack_maxsize;
cont->saved_thread.fiber = th->fiber;
cont->saved_thread.local_storage = 0;
cont->saved_thread.local_storage_recursive_hash = Qnil;
cont->saved_thread.local_storage_recursive_hash_for_trace = Qnil;
cont->saved_thread.ec.local_storage = NULL;
cont->saved_thread.ec.local_storage_recursive_hash = Qnil;
cont->saved_thread.ec.local_storage_recursive_hash_for_trace = Qnil;
}
static rb_context_t *
@ -554,11 +553,6 @@ cont_restore_thread(rb_context_t *cont)
/* fiber */
th->ec = sth->ec;
sth->ec.stack = NULL;
th->local_storage = sth->local_storage;
th->local_storage_recursive_hash = sth->local_storage_recursive_hash;
th->local_storage_recursive_hash_for_trace = sth->local_storage_recursive_hash_for_trace;
th->fiber = (rb_fiber_t*)cont;
}
@ -1225,10 +1219,10 @@ fiber_init(VALUE fibval, VALUE proc)
0, /* local_size */
0);
th->ec.tag = 0;
th->local_storage = st_init_numtable();
th->local_storage_recursive_hash = Qnil;
th->local_storage_recursive_hash_for_trace = Qnil;
th->ec.tag = NULL;
th->ec.local_storage = NULL;
th->ec.local_storage_recursive_hash = Qnil;
th->ec.local_storage_recursive_hash_for_trace = Qnil;
th->first_proc = proc;
@ -1524,7 +1518,7 @@ rb_fiber_reset_root_local_storage(VALUE thval)
GetThreadPtr(thval, th);
if (th->root_fiber && th->root_fiber != th->fiber) {
th->local_storage = th->root_fiber->cont.saved_thread.local_storage;
th->ec.local_storage = th->root_fiber->cont.saved_thread.ec.local_storage;
}
}

Просмотреть файл

@ -3033,12 +3033,13 @@ static VALUE
threadptr_local_aref(rb_thread_t *th, ID id)
{
if (id == recursive_key) {
return th->local_storage_recursive_hash;
return th->ec.local_storage_recursive_hash;
}
else {
st_data_t val;
st_table *local_storage = th->ec.local_storage;
if (th->local_storage && st_lookup(th->local_storage, id, &val)) {
if (local_storage != NULL && st_lookup(local_storage, id, &val)) {
return (VALUE)val;
}
else {
@ -3143,39 +3144,46 @@ rb_thread_fetch(int argc, VALUE *argv, VALUE self)
GetThreadPtr(self, th);
if (id == recursive_key) {
return th->local_storage_recursive_hash;
return th->ec.local_storage_recursive_hash;
}
if (id && th->local_storage && st_lookup(th->local_storage, id, &val)) {
else if (id && th->ec.local_storage && st_lookup(th->ec.local_storage, id, &val)) {
return val;
}
if (block_given)
else if (block_given) {
return rb_yield(key);
else if (argc == 1)
}
else if (argc == 1) {
rb_raise(rb_eKeyError, "key not found: %"PRIsVALUE, key);
else
}
else {
return argv[1];
}
}
static VALUE
threadptr_local_aset(rb_thread_t *th, ID id, VALUE val)
{
if (id == recursive_key) {
th->local_storage_recursive_hash = val;
th->ec.local_storage_recursive_hash = val;
return val;
}
else if (NIL_P(val)) {
if (!th->local_storage) return Qnil;
st_delete_wrap(th->local_storage, id);
else {
st_table *local_storage = th->ec.local_storage;
if (NIL_P(val)) {
if (!local_storage) return Qnil;
st_delete_wrap(local_storage, id);
return Qnil;
}
else {
if (!th->local_storage) {
th->local_storage = st_init_numtable();
if (local_storage == NULL) {
th->ec.local_storage = local_storage = st_init_numtable();
}
st_insert(th->local_storage, id, val);
st_insert(local_storage, id, val);
return val;
}
}
}
VALUE
rb_thread_local_aset(VALUE thread, ID id, VALUE val)
@ -3286,17 +3294,21 @@ rb_thread_key_p(VALUE self, VALUE key)
{
rb_thread_t *th;
ID id = rb_check_id(&key);
st_table *local_storage;
GetThreadPtr(self, th);
local_storage= th->ec.local_storage;
if (!id || !th->local_storage) {
if (!id || local_storage == NULL) {
return Qfalse;
}
if (st_lookup(th->local_storage, id, 0)) {
else if (st_lookup(local_storage, id, 0)) {
return Qtrue;
}
else {
return Qfalse;
}
}
static int
thread_keys_i(ID key, VALUE value, VALUE ary)
@ -3332,8 +3344,8 @@ rb_thread_keys(VALUE self)
VALUE ary = rb_ary_new();
GetThreadPtr(self, th);
if (th->local_storage) {
st_foreach(th->local_storage, thread_keys_i, ary);
if (th->ec.local_storage) {
st_foreach(th->ec.local_storage, thread_keys_i, ary);
}
return ary;
}
@ -4512,13 +4524,13 @@ rb_thread_shield_destroy(VALUE self)
static VALUE
threadptr_recursive_hash(rb_thread_t *th)
{
return th->local_storage_recursive_hash;
return th->ec.local_storage_recursive_hash;
}
static void
threadptr_recursive_hash_set(rb_thread_t *th, VALUE hash)
{
th->local_storage_recursive_hash = hash;
th->ec.local_storage_recursive_hash = hash;
}
ID rb_frame_last_func(void);

18
vm.c
Просмотреть файл

@ -2417,9 +2417,9 @@ rb_thread_mark(void *ptr)
RUBY_MARK_UNLESS_NULL(th->locking_mutex);
rb_mark_tbl(th->local_storage);
RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash);
RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash_for_trace);
rb_mark_tbl(th->ec.local_storage);
RUBY_MARK_UNLESS_NULL(th->ec.local_storage_recursive_hash);
RUBY_MARK_UNLESS_NULL(th->ec.local_storage_recursive_hash_for_trace);
RUBY_MARK_UNLESS_NULL(th->name);
@ -2445,8 +2445,8 @@ thread_free(void *ptr)
rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes);
}
if (th->local_storage) {
st_free_table(th->local_storage);
if (th->ec.local_storage) {
st_free_table(th->ec.local_storage);
}
if (th->vm && th->vm->main_thread == th) {
@ -2475,8 +2475,8 @@ thread_memsize(const void *ptr)
if (!th->root_fiber) {
size += th->ec.stack_size * sizeof(VALUE);
}
if (th->local_storage) {
size += st_memsize(th->local_storage);
if (th->ec.local_storage) {
size += st_memsize(th->ec.local_storage);
}
return size;
}
@ -2540,8 +2540,8 @@ th_init(rb_thread_t *th, VALUE self)
th->errinfo = Qnil;
th->last_status = Qnil;
th->root_svar = Qfalse;
th->local_storage_recursive_hash = Qnil;
th->local_storage_recursive_hash_for_trace = Qnil;
th->ec.local_storage_recursive_hash = Qnil;
th->ec.local_storage_recursive_hash_for_trace = Qnil;
#ifdef NON_SCALAR_THREAD_ID
th->thread_id_string[0] = '\0';
#endif

Просмотреть файл

@ -743,6 +743,11 @@ typedef struct rb_thread_context_struct {
int safe_level;
int raised_flag;
/* storage (ec (fiber) local) */
st_table *local_storage;
VALUE local_storage_recursive_hash;
VALUE local_storage_recursive_hash_for_trace;
} rb_execution_context_t;
typedef struct rb_thread_struct {
@ -806,11 +811,6 @@ typedef struct rb_thread_struct {
VALUE locking_mutex;
struct rb_mutex_struct *keeping_mutexes;
/* storage */
st_table *local_storage;
VALUE local_storage_recursive_hash;
VALUE local_storage_recursive_hash_for_trace;
rb_thread_list_t *join_list;
VALUE first_proc;

Просмотреть файл

@ -329,10 +329,10 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
if (th->trace_arg == 0 && /* check reentrant */
trace_arg->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) {
const VALUE errinfo = th->errinfo;
const VALUE old_recursive = th->local_storage_recursive_hash;
const VALUE old_recursive = th->ec.local_storage_recursive_hash;
int state = 0;
th->local_storage_recursive_hash = th->local_storage_recursive_hash_for_trace;
th->ec.local_storage_recursive_hash = th->ec.local_storage_recursive_hash_for_trace;
th->errinfo = Qnil;
th->vm->trace_running++;
@ -352,8 +352,8 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
th->trace_arg = 0;
th->vm->trace_running--;
th->local_storage_recursive_hash_for_trace = th->local_storage_recursive_hash;
th->local_storage_recursive_hash = old_recursive;
th->ec.local_storage_recursive_hash_for_trace = th->ec.local_storage_recursive_hash;
th->ec.local_storage_recursive_hash = old_recursive;
if (state) {
if (pop_p) {