diff options
author | Samuel Williams <[email protected]> | 2024-11-21 10:38:13 +1300 |
---|---|---|
committer | Samuel Williams <[email protected]> | 2025-04-14 18:28:09 +0900 |
commit | 4e970c5d5aee94c729541236c69792ec314f3731 (patch) | |
tree | 298baeb38bbc456e9615b7656f4aa0d5b304a6bf /spec/ruby/optional/capi | |
parent | 22667fcc38f6246f8d93f229097375f85e3efbab (diff) |
Expose `ruby_thread_has_gvl_p`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11975
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r-- | spec/ruby/optional/capi/ext/thread_spec.c | 10 | ||||
-rw-r--r-- | spec/ruby/optional/capi/thread_spec.rb | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/spec/ruby/optional/capi/ext/thread_spec.c b/spec/ruby/optional/capi/ext/thread_spec.c index 3511c2fbcf..6ee111b7b7 100644 --- a/spec/ruby/optional/capi/ext/thread_spec.c +++ b/spec/ruby/optional/capi/ext/thread_spec.c @@ -118,7 +118,6 @@ static VALUE thread_spec_rb_thread_wait_for(VALUE self, VALUE s, VALUE ms) { return Qnil; } - VALUE thread_spec_call_proc(void *arg_ptr) { VALUE arg_array = (VALUE)arg_ptr; VALUE arg = rb_ary_pop(arg_array); @@ -167,6 +166,12 @@ static VALUE thread_spec_ruby_native_thread_p_new_thread(VALUE self) { #endif } +#ifdef RUBY_VERSION_IS_3_5 +static VALUE thread_spec_ruby_thread_has_gvl_p(VALUE self) { + return ruby_thread_has_gvl_p() ? Qtrue : Qfalse; +} +#endif + void Init_thread_spec(void) { VALUE cls = rb_define_class("CApiThreadSpecs", rb_cObject); rb_define_method(cls, "rb_thread_alone", thread_spec_rb_thread_alone, 0); @@ -180,6 +185,9 @@ void Init_thread_spec(void) { rb_define_method(cls, "rb_thread_create", thread_spec_rb_thread_create, 2); rb_define_method(cls, "ruby_native_thread_p", thread_spec_ruby_native_thread_p, 0); rb_define_method(cls, "ruby_native_thread_p_new_thread", thread_spec_ruby_native_thread_p_new_thread, 0); +#ifdef RUBY_VERSION_IS_3_5 + rb_define_method(cls, "ruby_thread_has_gvl_p", thread_spec_ruby_thread_has_gvl_p, 0); +#endif } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/thread_spec.rb b/spec/ruby/optional/capi/thread_spec.rb index af641f0564..cd9ae8ff19 100644 --- a/spec/ruby/optional/capi/thread_spec.rb +++ b/spec/ruby/optional/capi/thread_spec.rb @@ -184,4 +184,12 @@ describe "C-API Thread function" do thr.value.should be_true end end + + ruby_version_is "3.5" do + describe "ruby_thread_has_gvl_p" do + it "returns true if the current thread has the GVL" do + @t.ruby_thread_has_gvl_p.should be_true + end + end + end end |