[前][次][番号順一覧][スレッド一覧]

ruby-changes:69662

From: Koichi <ko1@a...>
Date: Tue, 9 Nov 2021 16:21:31 +0900 (JST)
Subject: [ruby-changes:69662] 5680c38c75 (master): Use valid `ec` for postponed job.

https://git.ruby-lang.org/ruby.git/commit/?id=5680c38c75

From 5680c38c75aeb5cbd219aafa8eb48c315f287d97 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 9 Nov 2021 03:37:17 +0900
Subject: Use valid `ec` for postponed job.

Postponed job can be registered from non-Ruby thread, which means
`ec` in TLS can be NULL. In this case, use main thread's `ec` instead.

See https://github.com/ruby/ruby/pull/4108
and https://github.com/ruby/ruby/pull/4336
---
 vm_trace.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/vm_trace.c b/vm_trace.c
index 63e4c3ac1a9..3bc55f2c3ab 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -1582,6 +1582,14 @@ postponed_job_register(rb_execution_context_t *ec, rb_vm_t *vm, https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1582
     return PJRR_SUCCESS;
 }
 
+static rb_execution_context_t *
+get_valid_ec(rb_vm_t *vm)
+{
+    rb_execution_context_t *ec = GET_EC();
+    if (ec == NULL) ec = rb_vm_main_ractor_ec(vm);
+    return ec;
+}
+
 /*
  * return 0 if job buffer is full
  * Async-signal-safe
@@ -1589,8 +1597,8 @@ postponed_job_register(rb_execution_context_t *ec, rb_vm_t *vm, https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1597
 int
 rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data)
 {
-    rb_execution_context_t *ec = GET_EC();
-    rb_vm_t *vm = rb_ec_vm_ptr(ec);
+    rb_vm_t *vm = GET_VM();
+    rb_execution_context_t *ec = get_valid_ec(vm);
 
   begin:
     switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) {
@@ -1608,8 +1616,8 @@ rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1616
 int
 rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data)
 {
-    rb_execution_context_t *ec = GET_EC();
-    rb_vm_t *vm = rb_ec_vm_ptr(ec);
+    rb_vm_t *vm = GET_VM();
+    rb_execution_context_t *ec = get_valid_ec(vm);
     rb_postponed_job_t *pjob;
     rb_atomic_t i, index;
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]