From 9deffc6d4162227af86d7b2ac2d1305a82ce8f72 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 26 Apr 2026 21:22:36 +0900 Subject: [PATCH] Fix ruby_whisper_lock_gvl and ruby_whisper_unlock_gvl --- bindings/ruby/ext/ruby_whisper.c | 8 ++++---- bindings/ruby/ext/ruby_whisper_context.c | 12 +++++------ bindings/ruby/ext/ruby_whisper_params.c | 20 +++++++++---------- bindings/ruby/ext/ruby_whisper_transcribe.cpp | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bindings/ruby/ext/ruby_whisper.c b/bindings/ruby/ext/ruby_whisper.c index b1a0d6a4..7478d790 100644 --- a/bindings/ruby/ext/ruby_whisper.c +++ b/bindings/ruby/ext/ruby_whisper.c @@ -109,15 +109,15 @@ static VALUE ruby_whisper_s_finalize_log_callback(VALUE self, VALUE id) { } void -ruby_whisper_lock_gvl(void) +ruby_whisper_gvl_locked(void) { - is_without_gvl = true; + is_without_gvl = false; } void -ruby_whisper_unlock_gvl(void) +ruby_whisper_gvl_unlocked(void) { - is_without_gvl = false; + is_without_gvl = true; } typedef struct { diff --git a/bindings/ruby/ext/ruby_whisper_context.c b/bindings/ruby/ext/ruby_whisper_context.c index 65c3d906..42f6fbdb 100644 --- a/bindings/ruby/ext/ruby_whisper_context.c +++ b/bindings/ruby/ext/ruby_whisper_context.c @@ -23,8 +23,8 @@ extern VALUE ruby_whisper_transcribe(int argc, VALUE *argv, VALUE self); extern VALUE rb_whisper_model_s_new(VALUE context); extern VALUE rb_whisper_segment_s_new(VALUE context, int index); extern void prepare_transcription(ruby_whisper_params *rwp, VALUE *context, int n_processors); -extern void ruby_whisper_lock_gvl(void); -extern void ruby_whisper_unlock_gvl(void); +extern void ruby_whisper_gvl_locked(void); +extern void ruby_whisper_gvl_unlocked(void); ID transcribe_option_names[1]; @@ -454,7 +454,7 @@ release_samples(VALUE rb_parsed_args) static void* full_without_gvl(void *rb_args) { - ruby_whisper_unlock_gvl(); + ruby_whisper_gvl_unlocked(); full_without_gvl_args *args = (full_without_gvl_args *)rb_args; args->result = whisper_full(args->context, *args->params, args->samples, args->n_samples); @@ -492,7 +492,7 @@ full_body(VALUE rb_args) rwp->abort_callback_container, }; rb_thread_call_without_gvl(full_without_gvl, (void *)&full_without_gvl_args, full_ubf, (void *)&full_ubf_args); - ruby_whisper_lock_gvl(); + ruby_whisper_gvl_locked(); return INT2NUM(full_without_gvl_args.result); } @@ -534,7 +534,7 @@ VALUE ruby_whisper_full(int argc, VALUE *argv, VALUE self) static void* full_parallel_without_gvl(void *rb_args) { - ruby_whisper_unlock_gvl(); + ruby_whisper_gvl_unlocked(); full_parallel_without_gvl_args *args = (full_parallel_without_gvl_args *)rb_args; args->result = whisper_full_parallel(args->context, *args->params, args->samples, args->n_samples, args->n_processors); @@ -565,7 +565,7 @@ full_parallel_body(VALUE rb_args) rwp->abort_callback_container, }; rb_thread_call_without_gvl(full_parallel_without_gvl, (void *)&full_parallel_without_gvl_args, full_ubf, (void *)&full_ubf_args); - ruby_whisper_lock_gvl(); + ruby_whisper_gvl_locked(); return INT2NUM(full_parallel_without_gvl_args.result); } diff --git a/bindings/ruby/ext/ruby_whisper_params.c b/bindings/ruby/ext/ruby_whisper_params.c index 40935076..d8fa8e69 100644 --- a/bindings/ruby/ext/ruby_whisper_params.c +++ b/bindings/ruby/ext/ruby_whisper_params.c @@ -33,8 +33,8 @@ extern VALUE mWhisper; extern ID id_call; -extern void ruby_whisper_lock_gvl(void); -extern void ruby_whisper_unlock_gvl(void); +extern void ruby_whisper_gvl_locked(void); +extern void ruby_whisper_gvl_unlocked(void); extern VALUE ruby_whisper_normalize_model_path(VALUE model_path); extern VALUE rb_whisper_segment_s_new(VALUE context, int index); extern const rb_data_type_t ruby_whisper_vad_params_type; @@ -139,7 +139,7 @@ typedef struct { static void* call_new_segment_callbacks(void *v_args) { - ruby_whisper_lock_gvl(); + ruby_whisper_gvl_locked(); call_new_segment_callbacks_args *args = (call_new_segment_callbacks_args *)v_args; const ruby_whisper_callback_container *container = args->container; @@ -183,7 +183,7 @@ static void new_segment_callback(struct whisper_context *ctx, struct whisper_sta n_new }; rb_thread_call_with_gvl(call_new_segment_callbacks, (void *)&args); - ruby_whisper_unlock_gvl(); + ruby_whisper_gvl_unlocked(); } typedef struct { @@ -194,7 +194,7 @@ typedef struct { static void* call_progress_callbacks(void *v_args) { - ruby_whisper_lock_gvl(); + ruby_whisper_gvl_locked(); call_progress_callbacks_args *args = (call_progress_callbacks_args *)v_args; const ruby_whisper_callback_container *container = args->container; @@ -232,7 +232,7 @@ static void progress_callback(struct whisper_context *ctx, struct whisper_state progress_cur }; rb_thread_call_with_gvl(call_progress_callbacks, (void *)&args); - ruby_whisper_unlock_gvl(); + ruby_whisper_gvl_unlocked(); } typedef struct { @@ -243,7 +243,7 @@ typedef struct { static void* call_encoder_begin_callbacks(void *v_args) { - ruby_whisper_lock_gvl(); + ruby_whisper_gvl_locked(); call_encoder_begin_callbacks_args *args = (call_encoder_begin_callbacks_args *)v_args; const ruby_whisper_callback_container *container = args->container; @@ -288,7 +288,7 @@ static bool encoder_begin_callback(struct whisper_context *ctx, struct whisper_s true }; rb_thread_call_with_gvl(call_encoder_begin_callbacks, (void *)&args); - ruby_whisper_unlock_gvl(); + ruby_whisper_gvl_unlocked(); return args.is_continued; } @@ -301,7 +301,7 @@ typedef struct { static void* call_abort_callbacks(void *v_args) { - ruby_whisper_lock_gvl(); + ruby_whisper_gvl_locked(); call_abort_callbacks_args *args = (call_abort_callbacks_args *)v_args; const ruby_whisper_abort_callback_container *container = args->container; @@ -354,7 +354,7 @@ static bool abort_callback(void * user_data) { false }; rb_thread_call_with_gvl(call_abort_callbacks, (void *)&args); - ruby_whisper_unlock_gvl(); + ruby_whisper_gvl_unlocked(); return args.is_interrupted; } diff --git a/bindings/ruby/ext/ruby_whisper_transcribe.cpp b/bindings/ruby/ext/ruby_whisper_transcribe.cpp index c93b6ba3..082b3e4a 100644 --- a/bindings/ruby/ext/ruby_whisper_transcribe.cpp +++ b/bindings/ruby/ext/ruby_whisper_transcribe.cpp @@ -16,8 +16,8 @@ extern ID id_to_path; extern ID transcribe_option_names[1]; extern void prepare_transcription(ruby_whisper_params * rwp, VALUE * self, int n_processors); -extern void ruby_whisper_lock_gvl(void); -extern void ruby_whisper_unlock_gvl(void); +extern void ruby_whisper_gvl_locked(void); +extern void ruby_whisper_gvl_unlocked(void); typedef struct transcribe_without_gvl_args { struct whisper_context *context;