Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/kthread.h>
0003 #include <linux/wait.h>
0004 
0005 #include "spk_types.h"
0006 #include "speakup.h"
0007 #include "spk_priv.h"
0008 
0009 DECLARE_WAIT_QUEUE_HEAD(speakup_event);
0010 EXPORT_SYMBOL_GPL(speakup_event);
0011 
0012 int speakup_thread(void *data)
0013 {
0014     unsigned long flags;
0015     int should_break;
0016     struct bleep our_sound;
0017 
0018     our_sound.active = 0;
0019     our_sound.freq = 0;
0020     our_sound.jiffies = 0;
0021 
0022     mutex_lock(&spk_mutex);
0023     while (1) {
0024         DEFINE_WAIT(wait);
0025 
0026         while (1) {
0027             spin_lock_irqsave(&speakup_info.spinlock, flags);
0028             our_sound = spk_unprocessed_sound;
0029             spk_unprocessed_sound.active = 0;
0030             prepare_to_wait(&speakup_event, &wait,
0031                     TASK_INTERRUPTIBLE);
0032             should_break = kthread_should_stop() ||
0033                 our_sound.active ||
0034                 (synth && synth->catch_up && synth->alive &&
0035                     (speakup_info.flushing ||
0036                     !synth_buffer_empty()));
0037             spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0038             if (should_break)
0039                 break;
0040             mutex_unlock(&spk_mutex);
0041             schedule();
0042             mutex_lock(&spk_mutex);
0043         }
0044         finish_wait(&speakup_event, &wait);
0045         if (kthread_should_stop())
0046             break;
0047 
0048         if (our_sound.active)
0049             kd_mksound(our_sound.freq, our_sound.jiffies);
0050         if (synth && synth->catch_up && synth->alive) {
0051             /*
0052              * It is up to the callee to take the lock, so that it
0053              * can sleep whenever it likes
0054              */
0055             synth->catch_up(synth);
0056         }
0057 
0058         speakup_start_ttys();
0059     }
0060     mutex_unlock(&spk_mutex);
0061     return 0;
0062 }