diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-28 09:44:56 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-28 09:44:56 -0700 |
commit | e4c5bf8e3dca827a1b3a6fac494eae8c74b7e1e7 (patch) | |
tree | ea51b391f7d74ca695dcb9f5e46eb02688a92ed9 /drivers/staging/speakup/buffers.c | |
parent | 81280572ca6f54009edfa4deee563e8678784218 (diff) | |
parent | a4ac0d847af9dd34d5953a5e264400326144b6b2 (diff) | |
download | op-kernel-dev-e4c5bf8e3dca827a1b3a6fac494eae8c74b7e1e7.zip op-kernel-dev-e4c5bf8e3dca827a1b3a6fac494eae8c74b7e1e7.tar.gz |
Merge 'staging-next' to Linus's tree
This merges the staging-next tree to Linus's tree and resolves
some conflicts that were present due to changes in other trees that were
affected by files here.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/speakup/buffers.c')
-rw-r--r-- | drivers/staging/speakup/buffers.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/drivers/staging/speakup/buffers.c b/drivers/staging/speakup/buffers.c new file mode 100644 index 0000000..b7b60d5 --- /dev/null +++ b/drivers/staging/speakup/buffers.c @@ -0,0 +1,107 @@ +#include <linux/console.h> +#include <linux/smp_lock.h> +#include <linux/types.h> +#include <linux/wait.h> + +#include "speakup.h" +#include "spk_priv.h" + +#define synthBufferSize 8192 /* currently 8K bytes */ + +static u_char synth_buffer[synthBufferSize]; /* guess what this is for! */ +static u_char *buff_in = synth_buffer; +static u_char *buff_out = synth_buffer; +static u_char *buffer_end = synth_buffer+synthBufferSize-1; + +/* These try to throttle applications by stopping the TTYs + * Note: we need to make sure that we will restart them eventually, which is + * usually not possible to do from the notifiers. TODO: it should be possible + * starting from linux 2.6.26. + * + * So we only stop when we know alive == 1 (else we discard the data anyway), + * and the alive synth will eventually call start_ttys from the thread context. + */ +void speakup_start_ttys(void) +{ + int i; + + for (i = 0; i < MAX_NR_CONSOLES; i++) { + if (speakup_console[i] && speakup_console[i]->tty_stopped) + continue; + if ((vc_cons[i].d != NULL) && (vc_cons[i].d->port.tty != NULL)) + start_tty(vc_cons[i].d->port.tty); + } +} +EXPORT_SYMBOL_GPL(speakup_start_ttys); + +static void speakup_stop_ttys(void) +{ + int i; + + for (i = 0; i < MAX_NR_CONSOLES; i++) + if ((vc_cons[i].d != NULL) && (vc_cons[i].d->port.tty != NULL)) + stop_tty(vc_cons[i].d->port.tty); +} + +static int synth_buffer_free(void) +{ + int bytesFree; + + if (buff_in >= buff_out) + bytesFree = synthBufferSize - (buff_in - buff_out); + else + bytesFree = buff_out - buff_in; + return bytesFree; +} + +int synth_buffer_empty(void) +{ + return (buff_in == buff_out); +} +EXPORT_SYMBOL_GPL(synth_buffer_empty); + +void synth_buffer_add(char ch) +{ + if (!synth->alive) { + /* This makes sure that we won't stop TTYs if there is no synth + * to restart them */ + return; + } + if (synth_buffer_free() <= 100) { + synth_start(); + speakup_stop_ttys(); + } + if (synth_buffer_free() <= 1) + return; + *buff_in++ = ch; + if (buff_in > buffer_end) + buff_in = synth_buffer; +} + +char synth_buffer_getc(void) +{ + char ch; + + if (buff_out == buff_in) + return 0; + ch = *buff_out++; + if (buff_out > buffer_end) + buff_out = synth_buffer; + return ch; +} +EXPORT_SYMBOL_GPL(synth_buffer_getc); + +char synth_buffer_peek(void) +{ + if (buff_out == buff_in) + return 0; + return *buff_out; +} +EXPORT_SYMBOL_GPL(synth_buffer_peek); + +void synth_buffer_clear(void) +{ + buff_in = buff_out = synth_buffer; + return; +} +EXPORT_SYMBOL_GPL(synth_buffer_clear); |