mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Expose ruby_thread_has_gvl_p
.
This commit is contained in:
parent
22667fcc38
commit
4e970c5d5a
Notes:
git
2025-04-14 09:28:27 +00:00
4 changed files with 24 additions and 6 deletions
|
@ -333,6 +333,13 @@ void *rb_internal_thread_specific_get(VALUE thread_val, rb_internal_thread_speci
|
|||
*/
|
||||
void rb_internal_thread_specific_set(VALUE thread_val, rb_internal_thread_specific_key_t key, void *data);
|
||||
|
||||
/**
|
||||
* Whether the current thread is holding the GVL.
|
||||
*
|
||||
* @return true if the current thread is holding the GVL, false otherwise.
|
||||
*/
|
||||
int ruby_thread_has_gvl_p(void);
|
||||
|
||||
RBIMPL_SYMBOL_EXPORT_END()
|
||||
|
||||
#endif /* RUBY_THREAD_H */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
5
thread.c
5
thread.c
|
@ -1937,11 +1937,6 @@ rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
|
|||
|
||||
/*
|
||||
* ruby_thread_has_gvl_p - check if current native thread has GVL.
|
||||
*
|
||||
***
|
||||
*** This API is EXPERIMENTAL!
|
||||
*** We do not guarantee that this API remains in ruby 1.9.2 or later.
|
||||
***
|
||||
*/
|
||||
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue