tty_mutex.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <linux/tty.h>
  2. #include <linux/module.h>
  3. #include <linux/kallsyms.h>
  4. #include <linux/semaphore.h>
  5. #include <linux/sched.h>
  6. /* Legacy tty mutex glue */
  7. /*
  8. * Getting the big tty mutex.
  9. */
  10. void __lockfunc tty_lock(struct tty_struct *tty)
  11. {
  12. if (tty->magic != TTY_MAGIC) {
  13. printk(KERN_ERR "L Bad %p\n", tty);
  14. WARN_ON(1);
  15. return;
  16. }
  17. tty_kref_get(tty);
  18. mutex_lock(&tty->legacy_mutex);
  19. }
  20. EXPORT_SYMBOL(tty_lock);
  21. void __lockfunc tty_unlock(struct tty_struct *tty)
  22. {
  23. if (tty->magic != TTY_MAGIC) {
  24. printk(KERN_ERR "U Bad %p\n", tty);
  25. WARN_ON(1);
  26. return;
  27. }
  28. mutex_unlock(&tty->legacy_mutex);
  29. tty_kref_put(tty);
  30. }
  31. EXPORT_SYMBOL(tty_unlock);
  32. /*
  33. * Getting the big tty mutex for a pair of ttys with lock ordering
  34. * On a non pty/tty pair tty2 can be NULL which is just fine.
  35. */
  36. void __lockfunc tty_lock_pair(struct tty_struct *tty,
  37. struct tty_struct *tty2)
  38. {
  39. if (tty < tty2) {
  40. tty_lock(tty);
  41. tty_lock(tty2);
  42. } else {
  43. if (tty2 && tty2 != tty)
  44. tty_lock(tty2);
  45. tty_lock(tty);
  46. }
  47. }
  48. EXPORT_SYMBOL(tty_lock_pair);
  49. void __lockfunc tty_unlock_pair(struct tty_struct *tty,
  50. struct tty_struct *tty2)
  51. {
  52. tty_unlock(tty);
  53. if (tty2 && tty2 != tty)
  54. tty_unlock(tty2);
  55. }
  56. EXPORT_SYMBOL(tty_unlock_pair);