aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-27 01:56:38 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-27 01:56:38 +0000
commit9c6deac2d1ea29002f4af33b9c1c15aa2d4c34b7 (patch)
tree27c26fc0361f7fd62cfdc5c8520f315bb78f7527 /thread.c
parent969057c95a4d8c26cf58dd99dff3dbface11f1cd (diff)
downloadruby-9c6deac2d1ea29002f4af33b9c1c15aa2d4c34b7.tar.gz
* vm_core.h: add rb_thread_t::local_storage_recursive_hash
to speed up Thread#[:__recursive_key__] access. [Bug #10511] * thread.c (threadptr_local_aref): add fast path for :__recursive_data__. * thread.c (threadptr_recursive_hash, threadptr_recursive_hash_set): add special accessor for recursive hash. * cont.c: store/restore local_storage_recursive_hash. * vm.c: init and mark local_storage_recursive_hash. * vm_trace.c (rb_threadptr_exec_event_hooks_orig): clear and restore local_storage_recursive_hash directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c68
1 files changed, 40 insertions, 28 deletions
diff --git a/thread.c b/thread.c
index a8cc250239..97c4ab903b 100644
--- a/thread.c
+++ b/thread.c
@@ -2753,15 +2753,25 @@ rb_thread_inspect(VALUE thread)
return rb_thread_inspect_msg(thread, 1, 1, 1);
}
+/* variables for recursive traversals */
+static ID recursive_key;
+
static VALUE
threadptr_local_aref(rb_thread_t *th, ID id)
{
- st_data_t val;
+ if (id == recursive_key) {
+ return th->local_storage_recursive_hash;
+ }
+ else {
+ st_data_t val;
- if (th->local_storage && st_lookup(th->local_storage, id, &val)) {
- return (VALUE)val;
+ if (th->local_storage && st_lookup(th->local_storage, id, &val)) {
+ return (VALUE)val;
+ }
+ else {
+ return Qnil;
+ }
}
- return Qnil;
}
VALUE
@@ -2843,16 +2853,22 @@ rb_thread_aref(VALUE thread, VALUE key)
static VALUE
threadptr_local_aset(rb_thread_t *th, ID id, VALUE val)
{
- if (NIL_P(val)) {
+ if (id == recursive_key) {
+ th->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);
return Qnil;
}
- if (!th->local_storage) {
- th->local_storage = st_init_numtable();
+ else {
+ if (!th->local_storage) {
+ th->local_storage = st_init_numtable();
+ }
+ st_insert(th->local_storage, id, val);
+ return val;
}
- st_insert(th->local_storage, id, val);
- return val;
}
VALUE
@@ -4659,9 +4675,6 @@ rb_thread_shield_destroy(VALUE self)
return rb_thread_shield_waiting(self) > 0 ? Qtrue : Qfalse;
}
-/* variables for recursive traversals */
-static ID recursive_key;
-
static VALUE
ident_hash_new(void)
{
@@ -4670,6 +4683,18 @@ ident_hash_new(void)
return hash;
}
+static VALUE
+threadptr_recursive_hash(rb_thread_t *th)
+{
+ return th->local_storage_recursive_hash;
+}
+
+static void
+threadptr_recursive_hash_set(rb_thread_t *th, VALUE hash)
+{
+ th->local_storage_recursive_hash = hash;
+}
+
/*
* Returns the current "recursive list" used to detect recursion.
* This list is a hash table, unique for the current thread and for
@@ -4679,12 +4704,13 @@ ident_hash_new(void)
static VALUE
recursive_list_access(void)
{
- volatile VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key);
+ rb_thread_t *th = GET_THREAD();
+ VALUE hash = threadptr_recursive_hash(th);
VALUE sym = ID2SYM(rb_frame_this_func());
VALUE list;
if (NIL_P(hash) || !RB_TYPE_P(hash, T_HASH)) {
hash = ident_hash_new();
- rb_thread_local_aset(rb_thread_current(), recursive_key, hash);
+ threadptr_recursive_hash_set(th, hash);
list = Qnil;
}
else {
@@ -4697,20 +4723,6 @@ recursive_list_access(void)
return list;
}
-VALUE
-rb_threadptr_reset_recursive_data(rb_thread_t *th)
-{
- VALUE old = threadptr_local_aref(th, recursive_key);
- threadptr_local_aset(th, recursive_key, Qnil);
- return old;
-}
-
-void
-rb_threadptr_restore_recursive_data(rb_thread_t *th, VALUE old)
-{
- threadptr_local_aset(th, recursive_key, old);
-}
-
/*
* Returns Qtrue iff obj_id (or the pair <obj, paired_obj>) is already
* in the recursion list.