is_active -> is_open
This commit is contained in:
parent
2864933f8b
commit
ae4d63ccd3
|
|
@ -46,7 +46,7 @@ typedef struct ruby_whisper_log {
|
|||
typedef struct ruby_whisper_log_queue {
|
||||
rb_nativethread_lock_t lock;
|
||||
rb_nativethread_cond_t cond;
|
||||
bool is_active;
|
||||
bool is_open;
|
||||
|
||||
size_t head;
|
||||
size_t tail;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ ruby_whisper_log_queue_initialize(ruby_whisper_log_queue *log_queue)
|
|||
log_queue->head = 0;
|
||||
log_queue->tail = 0;
|
||||
log_queue->size = 0;
|
||||
log_queue->is_active = true;
|
||||
log_queue->is_open = true;
|
||||
log_queue->logs = ALLOC_N(ruby_whisper_log, LOG_QUEUE_CAPACITY);
|
||||
for (size_t i = 0; i < LOG_QUEUE_CAPACITY; i++) {
|
||||
// we cannot call Ruby API like ALLOC_N because this slot may realloced without GVL
|
||||
|
|
@ -31,21 +31,21 @@ ruby_whisper_log_queue_initialize(ruby_whisper_log_queue *log_queue)
|
|||
}
|
||||
|
||||
void
|
||||
ruby_whisper_log_queue_activate(ruby_whisper_log_queue *log_queue)
|
||||
ruby_whisper_log_queue_open(ruby_whisper_log_queue *log_queue)
|
||||
{
|
||||
rb_nativethread_lock_lock(&log_queue->lock);
|
||||
|
||||
log_queue->is_active = true;
|
||||
log_queue->is_open = true;
|
||||
|
||||
rb_nativethread_lock_unlock(&log_queue->lock);
|
||||
}
|
||||
|
||||
void
|
||||
ruby_whisper_log_queue_deactivate(ruby_whisper_log_queue *log_queue)
|
||||
ruby_whisper_log_queue_close(ruby_whisper_log_queue *log_queue)
|
||||
{
|
||||
rb_nativethread_lock_lock(&log_queue->lock);
|
||||
|
||||
log_queue->is_active = false;
|
||||
log_queue->is_open = false;
|
||||
rb_native_cond_broadcast(&log_queue->cond);
|
||||
|
||||
rb_nativethread_lock_unlock(&log_queue->lock);
|
||||
|
|
@ -65,7 +65,7 @@ ruby_whisper_log_queue_enqueue(ruby_whisper_log_queue *log_queue, enum ggml_log_
|
|||
{
|
||||
rb_nativethread_lock_lock(&log_queue->lock);
|
||||
|
||||
if (!log_queue->is_active) {
|
||||
if (!log_queue->is_open) {
|
||||
rb_nativethread_lock_unlock(&log_queue->lock);
|
||||
return;
|
||||
}
|
||||
|
|
@ -133,11 +133,11 @@ ruby_whisper_log_queue_drain(ruby_whisper_log_queue *log_queue)
|
|||
|
||||
rb_nativethread_lock_lock(&log_queue->lock);
|
||||
|
||||
while (log_queue->size == 0 && log_queue->is_active) {
|
||||
while (log_queue->size == 0 && log_queue->is_open) {
|
||||
rb_thread_call_without_gvl(ruby_whisper_log_queue_wait, (void *)log_queue, ruby_whisper_log_queue_wait_ubf, (void *)log_queue);
|
||||
}
|
||||
|
||||
if (log_queue->size == 0 && !log_queue->is_active) {
|
||||
if (log_queue->size == 0 && !log_queue->is_open) {
|
||||
rb_native_cond_broadcast(&log_queue->cond);
|
||||
rb_nativethread_lock_unlock(&log_queue->lock);
|
||||
return Qnil;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
extern VALUE mParakeet;
|
||||
|
||||
extern void ruby_whisper_log_queue_initialize(ruby_whisper_log_queue *log_queue);
|
||||
extern void ruby_whisper_log_queue_activate(ruby_whisper_log_queue *log_queue);
|
||||
extern void ruby_whisper_log_queue_deactivate(ruby_whisper_log_queue *log_queue);
|
||||
extern void ruby_whisper_log_queue_open(ruby_whisper_log_queue *log_queue);
|
||||
extern void ruby_whisper_log_queue_close(ruby_whisper_log_queue *log_queue);
|
||||
extern void ruby_whisper_log_queue_enqueue(ruby_whisper_log_queue *log_queue, enum ggml_log_level level, const char *text);
|
||||
extern VALUE ruby_whisper_log_queue_drain(ruby_whisper_log_queue *log_queue);
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ ruby_whisper_parakeet_s_log_set(VALUE self, VALUE log_callback, VALUE user_data)
|
|||
} else {
|
||||
rb_iv_set(self, "@log_callback", log_callback);
|
||||
rb_iv_set(self, "@log_callback_user_data", user_data);
|
||||
ruby_whisper_log_queue_activate(¶keet_log_queue);
|
||||
ruby_whisper_log_queue_open(¶keet_log_queue);
|
||||
rb_funcall(mParakeet, id_start_log_callback_thread, 0);
|
||||
parakeet_log_set(ruby_whisper_parakeet_log_callback, NULL);
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ ruby_whisper_parakeet_end_proc(VALUE args)
|
|||
ID id_alive = rb_intern("alive?");
|
||||
ID id_join = rb_intern("join");
|
||||
|
||||
ruby_whisper_log_queue_deactivate(¶keet_log_queue);
|
||||
ruby_whisper_log_queue_close(¶keet_log_queue);
|
||||
VALUE log_callback_thread = rb_ivar_get(mParakeet, id_log_callback_thread);
|
||||
if (!NIL_P(log_callback_thread) && RTEST(rb_funcall(log_callback_thread, id_alive, 0))) {
|
||||
rb_funcall(log_callback_thread, id_join, 0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue