Commit | Line | Data |
---|---|---|
c6e3fd22 WH |
1 | #include <linux/kthread.h> |
2 | #include <linux/wait.h> | |
3 | ||
4 | #include "spk_types.h" | |
5 | #include "speakup.h" | |
6 | #include "spk_priv.h" | |
7 | ||
8 | DECLARE_WAIT_QUEUE_HEAD(speakup_event); | |
9 | EXPORT_SYMBOL_GPL(speakup_event); | |
10 | ||
11 | int speakup_thread(void *data) | |
12 | { | |
13 | unsigned long flags; | |
14 | int should_break; | |
15 | struct bleep our_sound; | |
16 | ||
17 | our_sound.active = 0; | |
18 | our_sound.freq = 0; | |
19 | our_sound.jiffies = 0; | |
20 | ||
21 | mutex_lock(&spk_mutex); | |
22 | while (1) { | |
23 | DEFINE_WAIT(wait); | |
472fe30e | 24 | |
7025005f | 25 | while (1) { |
939d84ee | 26 | spin_lock_irqsave(&speakup_info.spinlock, flags); |
ca2beaf8 ST |
27 | our_sound = spk_unprocessed_sound; |
28 | spk_unprocessed_sound.active = 0; | |
7025005f WH |
29 | prepare_to_wait(&speakup_event, &wait, |
30 | TASK_INTERRUPTIBLE); | |
c6e3fd22 WH |
31 | should_break = kthread_should_stop() || |
32 | our_sound.active || | |
33 | (synth && synth->catch_up && synth->alive && | |
34 | (speakup_info.flushing || | |
35 | !synth_buffer_empty())); | |
939d84ee | 36 | spin_unlock_irqrestore(&speakup_info.spinlock, flags); |
c6e3fd22 WH |
37 | if (should_break) |
38 | break; | |
39 | mutex_unlock(&spk_mutex); | |
40 | schedule(); | |
41 | mutex_lock(&spk_mutex); | |
42 | } | |
43 | finish_wait(&speakup_event, &wait); | |
44 | if (kthread_should_stop()) | |
45 | break; | |
46 | ||
7025005f | 47 | if (our_sound.active) |
c6e3fd22 | 48 | kd_mksound(our_sound.freq, our_sound.jiffies); |
c6e3fd22 WH |
49 | if (synth && synth->catch_up && synth->alive) { |
50 | /* It is up to the callee to take the lock, so that it | |
13d825ed AF |
51 | * can sleep whenever it likes |
52 | */ | |
c6e3fd22 WH |
53 | synth->catch_up(synth); |
54 | } | |
55 | ||
56 | speakup_start_ttys(); | |
57 | } | |
58 | mutex_unlock(&spk_mutex); | |
59 | return 0; | |
60 | } |