Skip to content

Commit ff831eb

Browse files
committed
thead_sync.c: directly pass the execution context to yield
Saves one more call to GET_EC()
1 parent 7e7a1db commit ff831eb

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

internal/vm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const char *rb_type_str(enum ruby_value_type type);
6969
VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
7070
VALUE rb_check_funcall_basic_kw(VALUE, ID, VALUE, int, const VALUE*, int);
7171
VALUE rb_yield_1(VALUE val);
72+
VALUE rb_ec_yield(struct rb_execution_context_struct *ec, VALUE val);
7273
VALUE rb_yield_force_blockarg(VALUE values);
7374
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
7475
rb_block_call_func_t bl_proc, int min_argc, int max_argc,

thread_sync.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
650650
return rb_mut_sleep(GET_EC(), self, timeout);
651651
}
652652

653-
654653
VALUE
655654
rb_mutex_synchronize(VALUE self, VALUE (*func)(VALUE arg), VALUE arg)
656655
{
@@ -660,6 +659,12 @@ rb_mutex_synchronize(VALUE self, VALUE (*func)(VALUE arg), VALUE arg)
660659
return rb_ec_ensure(args.ec, func, arg, do_mutex_unlock_safe, (VALUE)&args);
661660
}
662661

662+
static VALUE
663+
do_ec_yield(VALUE _ec)
664+
{
665+
return rb_ec_yield((rb_execution_context_t *)_ec, Qundef);
666+
}
667+
663668
VALUE
664669
rb_mut_synchronize(rb_execution_context_t *ec, VALUE self)
665670
{
@@ -669,7 +674,7 @@ rb_mut_synchronize(rb_execution_context_t *ec, VALUE self)
669674
.ec = ec,
670675
};
671676
do_mutex_lock(&args, 1);
672-
return rb_ec_ensure(args.ec, rb_yield, Qundef, do_mutex_unlock_safe, (VALUE)&args);
677+
return rb_ec_ensure(args.ec, do_ec_yield, (VALUE)ec, do_mutex_unlock_safe, (VALUE)&args);
673678
}
674679

675680
void

vm_eval.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,17 @@ rb_yield(VALUE val)
13791379
}
13801380
}
13811381

1382+
VALUE
1383+
rb_ec_yield(rb_execution_context_t *ec, VALUE val)
1384+
{
1385+
if (UNDEF_P(val)) {
1386+
return vm_yield(ec, 0, NULL, RB_NO_KEYWORDS);
1387+
}
1388+
else {
1389+
return vm_yield(ec, 1, &val, RB_NO_KEYWORDS);
1390+
}
1391+
}
1392+
13821393
#undef rb_yield_values
13831394
VALUE
13841395
rb_yield_values(int n, ...)

0 commit comments

Comments
 (0)