Linux 4.19.133
[linux/fpc-iii.git] / drivers / staging / speakup / thread.c
blob2fc75e60fbac28c655ad84e1b65caa2f54f20809
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kthread.h>
3 #include <linux/wait.h>
5 #include "spk_types.h"
6 #include "speakup.h"
7 #include "spk_priv.h"
9 DECLARE_WAIT_QUEUE_HEAD(speakup_event);
10 EXPORT_SYMBOL_GPL(speakup_event);
12 int speakup_thread(void *data)
14 unsigned long flags;
15 int should_break;
16 struct bleep our_sound;
18 our_sound.active = 0;
19 our_sound.freq = 0;
20 our_sound.jiffies = 0;
22 mutex_lock(&spk_mutex);
23 while (1) {
24 DEFINE_WAIT(wait);
26 while (1) {
27 spin_lock_irqsave(&speakup_info.spinlock, flags);
28 our_sound = spk_unprocessed_sound;
29 spk_unprocessed_sound.active = 0;
30 prepare_to_wait(&speakup_event, &wait,
31 TASK_INTERRUPTIBLE);
32 should_break = kthread_should_stop() ||
33 our_sound.active ||
34 (synth && synth->catch_up && synth->alive &&
35 (speakup_info.flushing ||
36 !synth_buffer_empty()));
37 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
38 if (should_break)
39 break;
40 mutex_unlock(&spk_mutex);
41 schedule();
42 mutex_lock(&spk_mutex);
44 finish_wait(&speakup_event, &wait);
45 if (kthread_should_stop())
46 break;
48 if (our_sound.active)
49 kd_mksound(our_sound.freq, our_sound.jiffies);
50 if (synth && synth->catch_up && synth->alive) {
52 * It is up to the callee to take the lock, so that it
53 * can sleep whenever it likes
55 synth->catch_up(synth);
58 speakup_start_ttys();
60 mutex_unlock(&spk_mutex);
61 return 0;