2018-01-11 11:08:40 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-10-07 13:20:02 -05:00
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
|
|
|
|
#include "spk_types.h"
|
|
|
|
#include "speakup.h"
|
|
|
|
#include "spk_priv.h"
|
|
|
|
|
|
|
|
DECLARE_WAIT_QUEUE_HEAD(speakup_event);
|
|
|
|
EXPORT_SYMBOL_GPL(speakup_event);
|
|
|
|
|
|
|
|
int speakup_thread(void *data)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int should_break;
|
|
|
|
struct bleep our_sound;
|
|
|
|
|
|
|
|
our_sound.active = 0;
|
|
|
|
our_sound.freq = 0;
|
|
|
|
our_sound.jiffies = 0;
|
|
|
|
|
|
|
|
mutex_lock(&spk_mutex);
|
|
|
|
while (1) {
|
|
|
|
DEFINE_WAIT(wait);
|
2014-09-14 03:38:34 -07:00
|
|
|
|
2010-10-15 22:13:38 -05:00
|
|
|
while (1) {
|
2013-05-13 00:03:07 -05:00
|
|
|
spin_lock_irqsave(&speakup_info.spinlock, flags);
|
2013-01-02 02:37:40 +01:00
|
|
|
our_sound = spk_unprocessed_sound;
|
|
|
|
spk_unprocessed_sound.active = 0;
|
2010-10-15 22:13:38 -05:00
|
|
|
prepare_to_wait(&speakup_event, &wait,
|
2016-11-19 12:12:12 -05:00
|
|
|
TASK_INTERRUPTIBLE);
|
2010-10-07 13:20:02 -05:00
|
|
|
should_break = kthread_should_stop() ||
|
|
|
|
our_sound.active ||
|
|
|
|
(synth && synth->catch_up && synth->alive &&
|
|
|
|
(speakup_info.flushing ||
|
|
|
|
!synth_buffer_empty()));
|
2013-05-13 00:03:07 -05:00
|
|
|
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
|
2010-10-07 13:20:02 -05:00
|
|
|
if (should_break)
|
|
|
|
break;
|
|
|
|
mutex_unlock(&spk_mutex);
|
|
|
|
schedule();
|
|
|
|
mutex_lock(&spk_mutex);
|
|
|
|
}
|
|
|
|
finish_wait(&speakup_event, &wait);
|
|
|
|
if (kthread_should_stop())
|
|
|
|
break;
|
|
|
|
|
2010-10-15 22:13:38 -05:00
|
|
|
if (our_sound.active)
|
2010-10-07 13:20:02 -05:00
|
|
|
kd_mksound(our_sound.freq, our_sound.jiffies);
|
|
|
|
if (synth && synth->catch_up && synth->alive) {
|
2016-11-19 12:12:11 -05:00
|
|
|
/*
|
|
|
|
* It is up to the callee to take the lock, so that it
|
2015-08-14 22:34:37 +03:00
|
|
|
* can sleep whenever it likes
|
|
|
|
*/
|
2010-10-07 13:20:02 -05:00
|
|
|
synth->catch_up(synth);
|
|
|
|
}
|
|
|
|
|
|
|
|
speakup_start_ttys();
|
|
|
|
}
|
|
|
|
mutex_unlock(&spk_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|