summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-09 15:42:52 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-09 15:42:52 +0000
commitb5b1a2131ec5cbde6adaf0d37953ff05c393218b (patch)
tree9bb7cc204bb2f82b6efd3c0e4a77d034e6103cb5 /variable.c
parent2d909ca11f2d61171a9afca3ccca7e07db1e4527 (diff)
merge revision(s) 58587,58588: [Backport #13526]
variable.c: cleanup waitq upon thread death * variable.c (autoload_reset): use idempotent list_del_init (autoload_sleep): moved code from rb_autoload_load (autoload_sleep_done): cleanup for use with rb_ensure (rb_autoload_load): ensure list delete happens in case the thread dies during sleep * test/ruby/bug-13526.rb: new script for separate execution * test/ruby/test_autoload.rb (test_bug_13526): new test [ruby-core:81016] [Bug #13526] * properties. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@58637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/variable.c b/variable.c
index fadc8d1763..7f8cef94e0 100644
--- a/variable.c
+++ b/variable.c
@@ -2142,7 +2142,7 @@ autoload_reset(VALUE arg)
VALUE th = cur->thread;
cur->thread = Qfalse;
- list_del(&cur->waitq.node);
+ list_del_init(&cur->waitq.node); /* idempotent */
/*
* cur is stored on the stack of cur->waiting_th,
@@ -2155,6 +2155,34 @@ autoload_reset(VALUE arg)
return 0; /* ignored */
}
+static VALUE
+autoload_sleep(VALUE arg)
+{
+ struct autoload_state *state = (struct autoload_state *)arg;
+
+ /*
+ * autoload_reset in other thread will resume us and remove us
+ * from the waitq list
+ */
+ do {
+ rb_thread_sleep_deadly();
+ } while (state->thread != Qfalse);
+
+ return Qfalse;
+}
+
+static VALUE
+autoload_sleep_done(VALUE arg)
+{
+ struct autoload_state *state = (struct autoload_state *)arg;
+
+ if (state->thread != Qfalse && rb_thread_to_be_killed(state->thread)) {
+ list_del_init(&state->waitq.node); /* idempotent */
+ }
+
+ return Qfalse;
+}
+
VALUE
rb_autoload_load(VALUE mod, ID id)
{
@@ -2192,13 +2220,9 @@ rb_autoload_load(VALUE mod, ID id)
}
else {
list_add_tail(&ele->state->waitq.head, &state.waitq.node);
- /*
- * autoload_reset in other thread will resume us and remove us
- * from the waitq list
- */
- do {
- rb_thread_sleep_deadly();
- } while (state.thread != Qfalse);
+
+ rb_ensure(autoload_sleep, (VALUE)&state,
+ autoload_sleep_done, (VALUE)&state);
}
/* autoload_data_i can be deleted by another thread while require */