Path: blob/master/drivers/accessibility/speakup/thread.c
26282 views
// SPDX-License-Identifier: GPL-2.01#include <linux/kthread.h>2#include <linux/wait.h>34#include "spk_types.h"5#include "speakup.h"6#include "spk_priv.h"78DECLARE_WAIT_QUEUE_HEAD(speakup_event);9EXPORT_SYMBOL_GPL(speakup_event);1011int speakup_thread(void *data)12{13unsigned long flags;14int should_break;15struct bleep our_sound;1617our_sound.active = 0;18our_sound.freq = 0;19our_sound.jiffies = 0;2021mutex_lock(&spk_mutex);22while (1) {23DEFINE_WAIT(wait);2425while (1) {26spin_lock_irqsave(&speakup_info.spinlock, flags);27our_sound = spk_unprocessed_sound;28spk_unprocessed_sound.active = 0;29prepare_to_wait(&speakup_event, &wait,30TASK_INTERRUPTIBLE);31should_break = kthread_should_stop() ||32our_sound.active ||33(synth && synth->catch_up && synth->alive &&34(speakup_info.flushing ||35!synth_buffer_empty()));36spin_unlock_irqrestore(&speakup_info.spinlock, flags);37if (should_break)38break;39mutex_unlock(&spk_mutex);40schedule();41mutex_lock(&spk_mutex);42}43finish_wait(&speakup_event, &wait);44if (kthread_should_stop())45break;4647if (our_sound.active)48kd_mksound(our_sound.freq, our_sound.jiffies);49if (synth && synth->catch_up && synth->alive) {50/*51* It is up to the callee to take the lock, so that it52* can sleep whenever it likes53*/54synth->catch_up(synth);55}5657speakup_start_ttys();58}59mutex_unlock(&spk_mutex);60return 0;61}626364