diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-12-12 09:10:04 +0100 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2025-12-12 10:08:05 +0100 |
| commit | ff831eb0572b2d8f794acca478ea77c7bfefbc61 (patch) | |
| tree | 68a0989c9d3b9920348d424a5f6b57060a9c0212 | |
| parent | 7e7a1db579dad504a26e42d5f3efa5b2968389af (diff) | |
thead_sync.c: directly pass the execution context to yield
Saves one more call to GET_EC()
| -rw-r--r-- | internal/vm.h | 1 | ||||
| -rw-r--r-- | thread_sync.c | 9 | ||||
| -rw-r--r-- | vm_eval.c | 11 |
3 files changed, 19 insertions, 2 deletions
diff --git a/internal/vm.h b/internal/vm.h index 7fae590d19..09dfaf182e 100644 --- a/internal/vm.h +++ b/internal/vm.h @@ -69,6 +69,7 @@ const char *rb_type_str(enum ruby_value_type type); VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE); VALUE rb_check_funcall_basic_kw(VALUE, ID, VALUE, int, const VALUE*, int); VALUE rb_yield_1(VALUE val); +VALUE rb_ec_yield(struct rb_execution_context_struct *ec, VALUE val); VALUE rb_yield_force_blockarg(VALUE values); VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, int min_argc, int max_argc, diff --git a/thread_sync.c b/thread_sync.c index e54963a4fe..6af6aaddd6 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -650,7 +650,6 @@ rb_mutex_sleep(VALUE self, VALUE timeout) return rb_mut_sleep(GET_EC(), self, timeout); } - VALUE rb_mutex_synchronize(VALUE self, VALUE (*func)(VALUE arg), VALUE arg) { @@ -660,6 +659,12 @@ rb_mutex_synchronize(VALUE self, VALUE (*func)(VALUE arg), VALUE arg) return rb_ec_ensure(args.ec, func, arg, do_mutex_unlock_safe, (VALUE)&args); } +static VALUE +do_ec_yield(VALUE _ec) +{ + return rb_ec_yield((rb_execution_context_t *)_ec, Qundef); +} + VALUE rb_mut_synchronize(rb_execution_context_t *ec, VALUE self) { @@ -669,7 +674,7 @@ rb_mut_synchronize(rb_execution_context_t *ec, VALUE self) .ec = ec, }; do_mutex_lock(&args, 1); - return rb_ec_ensure(args.ec, rb_yield, Qundef, do_mutex_unlock_safe, (VALUE)&args); + return rb_ec_ensure(args.ec, do_ec_yield, (VALUE)ec, do_mutex_unlock_safe, (VALUE)&args); } void @@ -1379,6 +1379,17 @@ rb_yield(VALUE val) } } +VALUE +rb_ec_yield(rb_execution_context_t *ec, VALUE val) +{ + if (UNDEF_P(val)) { + return vm_yield(ec, 0, NULL, RB_NO_KEYWORDS); + } + else { + return vm_yield(ec, 1, &val, RB_NO_KEYWORDS); + } +} + #undef rb_yield_values VALUE rb_yield_values(int n, ...) |
