Skip to content

Commit f79582f

Browse files
committed
Spec that rb_thread_call_with_gvl() acquires the C-ext lock
1 parent 06b90a4 commit f79582f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

spec/truffle/capi/cext_lock_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
@t.has_lock_in_call_without_gvl?.should == false
3232
end
3333

34+
it "is acquired inside rb_thread_call_with_gvl" do
35+
@t.has_lock_in_call_with_gvl?.should == true
36+
end
37+
3438
it "is released inside rb_funcall" do
3539
@t.has_lock_in_rb_funcall?.should == false
3640
end

spec/truffle/capi/ext/truffleruby_lock_spec.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ static VALUE has_lock_in_call_without_gvl(VALUE self) {
2929
return rb_thread_call_without_gvl(called_without_gvl, 0, RUBY_UBF_IO, 0);
3030
}
3131

32+
static void* called_with_gvl(void* data) {
33+
return rb_tr_cext_lock_owned_p();
34+
}
35+
36+
static VALUE has_lock_in_call_with_gvl(VALUE self) {
37+
return rb_thread_call_with_gvl(called_with_gvl, 0);
38+
}
39+
3240
static VALUE has_lock_in_rb_funcall(VALUE self) {
3341
return rb_funcall(truffleCExt, rb_intern("rb_tr_cext_lock_owned_p"), 0);
3442
}
@@ -46,6 +54,7 @@ void Init_truffleruby_lock_spec(void) {
4654
VALUE cls = rb_define_class("CApiTruffleRubyLockSpecs", rb_cObject);
4755
rb_define_method(cls, "has_lock?", has_lock, 0);
4856
rb_define_method(cls, "has_lock_in_call_without_gvl?", has_lock_in_call_without_gvl, 0);
57+
rb_define_method(cls, "has_lock_in_call_with_gvl?", has_lock_in_call_with_gvl, 0);
4958
rb_define_method(cls, "has_lock_in_rb_funcall?", has_lock_in_rb_funcall, 0);
5059

5160
rb_ext_ractor_safe(true);

0 commit comments

Comments
 (0)