tty_mutex.c 1000 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * drivers/char/tty_lock.c
  3. */
  4. #include <linux/tty.h>
  5. #include <linux/module.h>
  6. #include <linux/kallsyms.h>
  7. #include <linux/semaphore.h>
  8. #include <linux/sched.h>
  9. /*
  10. * The 'big tty mutex'
  11. *
  12. * This mutex is taken and released by tty_lock() and tty_unlock(),
  13. * replacing the older big kernel lock.
  14. * It can no longer be taken recursively, and does not get
  15. * released implicitly while sleeping.
  16. *
  17. * Don't use in new code.
  18. */
  19. static DEFINE_MUTEX(big_tty_mutex);
  20. struct task_struct *__big_tty_mutex_owner;
  21. EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
  22. /*
  23. * Getting the big tty mutex.
  24. */
  25. void __lockfunc tty_lock(void)
  26. {
  27. struct task_struct *task = current;
  28. WARN_ON(__big_tty_mutex_owner == task);
  29. mutex_lock(&big_tty_mutex);
  30. __big_tty_mutex_owner = task;
  31. }
  32. EXPORT_SYMBOL(tty_lock);
  33. void __lockfunc tty_unlock(void)
  34. {
  35. struct task_struct *task = current;
  36. WARN_ON(__big_tty_mutex_owner != task);
  37. __big_tty_mutex_owner = NULL;
  38. mutex_unlock(&big_tty_mutex);
  39. }
  40. EXPORT_SYMBOL(tty_unlock);