aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
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 cfc987eb9e..6e883c7041 100644
--- a/variable.c
+++ b/variable.c
@@ -2095,7 +2095,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,
@@ -2108,6 +2108,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)
{
@@ -2145,13 +2173,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 */