1 #include <linux/console.h>
2 #include <linux/types.h>
3 #include <linux/wait.h>
8 #define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */
10 static u16 synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */
11 static u16 *buff_in = synth_buffer;
12 static u16 *buff_out = synth_buffer;
13 static u16 *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
15 /* These try to throttle applications by stopping the TTYs
16 * Note: we need to make sure that we will restart them eventually, which is
17 * usually not possible to do from the notifiers. TODO: it should be possible
18 * starting from linux 2.6.26.
20 * So we only stop when we know alive == 1 (else we discard the data anyway),
21 * and the alive synth will eventually call start_ttys from the thread context.
23 void speakup_start_ttys(void)
27 for (i = 0; i < MAX_NR_CONSOLES; i++) {
28 if (speakup_console[i] && speakup_console[i]->tty_stopped)
30 if ((vc_cons[i].d) && (vc_cons[i].d->port.tty))
31 start_tty(vc_cons[i].d->port.tty);
34 EXPORT_SYMBOL_GPL(speakup_start_ttys);
36 static void speakup_stop_ttys(void)
40 for (i = 0; i < MAX_NR_CONSOLES; i++)
41 if ((vc_cons[i].d && (vc_cons[i].d->port.tty)))
42 stop_tty(vc_cons[i].d->port.tty);
45 static int synth_buffer_free(void)
49 if (buff_in >= buff_out)
50 chars_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
52 chars_free = buff_out - buff_in;
56 int synth_buffer_empty(void)
58 return (buff_in == buff_out);
60 EXPORT_SYMBOL_GPL(synth_buffer_empty);
62 void synth_buffer_add(u16 ch)
65 /* This makes sure that we won't stop TTYs if there is no synth
70 if (synth_buffer_free() <= 100) {
74 if (synth_buffer_free() <= 1)
77 if (buff_in > buffer_end)
78 buff_in = synth_buffer;
81 u16 synth_buffer_getc(void)
85 if (buff_out == buff_in)
88 if (buff_out > buffer_end)
89 buff_out = synth_buffer;
92 EXPORT_SYMBOL_GPL(synth_buffer_getc);
94 u16 synth_buffer_peek(void)
96 if (buff_out == buff_in)
100 EXPORT_SYMBOL_GPL(synth_buffer_peek);
102 void synth_buffer_skip_nonlatin1(void)
104 while (buff_out != buff_in) {
105 if (*buff_out < 0x100)
108 if (buff_out > buffer_end)
109 buff_out = synth_buffer;
112 EXPORT_SYMBOL_GPL(synth_buffer_skip_nonlatin1);
114 void synth_buffer_clear(void)
116 buff_in = synth_buffer;
117 buff_out = synth_buffer;
119 EXPORT_SYMBOL_GPL(synth_buffer_clear);