tty_mutex.c 1.2 KB
Newer Older
1 2 3 4 5 6
#include <linux/tty.h>
#include <linux/module.h>
#include <linux/kallsyms.h>
#include <linux/semaphore.h>
#include <linux/sched.h>

A
Alan Cox 已提交
7 8
/* Legacy tty mutex glue */

9 10 11
/*
 * Getting the big tty mutex.
 */
A
Alan Cox 已提交
12

13
void __lockfunc tty_lock(struct tty_struct *tty)
14
{
15
	if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
A
Alan Cox 已提交
16 17
		return;
	tty_kref_get(tty);
18
	mutex_lock(&tty->legacy_mutex);
19 20 21
}
EXPORT_SYMBOL(tty_lock);

22 23
int tty_lock_interruptible(struct tty_struct *tty)
{
24 25
	int ret;

26 27 28
	if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
		return -EIO;
	tty_kref_get(tty);
29 30 31 32
	ret = mutex_lock_interruptible(&tty->legacy_mutex);
	if (ret)
		tty_kref_put(tty);
	return ret;
33 34
}

A
Alan Cox 已提交
35
void __lockfunc tty_unlock(struct tty_struct *tty)
36
{
37
	if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
A
Alan Cox 已提交
38 39 40
		return;
	mutex_unlock(&tty->legacy_mutex);
	tty_kref_put(tty);
41 42
}
EXPORT_SYMBOL(tty_unlock);
A
Alan Cox 已提交
43

44
void __lockfunc tty_lock_slave(struct tty_struct *tty)
A
Alan Cox 已提交
45
{
46
	if (tty && tty != tty->link)
47
		tty_lock(tty);
A
Alan Cox 已提交
48 49
}

50
void __lockfunc tty_unlock_slave(struct tty_struct *tty)
A
Alan Cox 已提交
51
{
52 53
	if (tty && tty != tty->link)
		tty_unlock(tty);
A
Alan Cox 已提交
54
}
55 56 57

void tty_set_lock_subclass(struct tty_struct *tty)
{
58
	lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
59
}