thread.c 1.3 KB

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