Module Name: src Committed By: riastradh Date: Wed Oct 26 23:41:49 UTC 2022
Modified Files: src/sys/kern: tty.c src/sys/sys: tty.h Log Message: tty(9): New ttylock, ttyunlock, ttylocked functions. These are wrappers around the global tty_lock for now (and the continued existence of the tty_lock variable is why the ttylock function has no underscore in its name). They will assist in converting drivers to per-tty locking later on. To generate a diff of this commit: cvs rdiff -u -r1.306 -r1.307 src/sys/kern/tty.c cvs rdiff -u -r1.102 -r1.103 src/sys/sys/tty.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/tty.c diff -u src/sys/kern/tty.c:1.306 src/sys/kern/tty.c:1.307 --- src/sys/kern/tty.c:1.306 Tue Oct 25 23:21:13 2022 +++ src/sys/kern/tty.c Wed Oct 26 23:41:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.306 2022/10/25 23:21:13 riastradh Exp $ */ +/* $NetBSD: tty.c,v 1.307 2022/10/26 23:41:49 riastradh Exp $ */ /*- * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.306 2022/10/25 23:21:13 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.307 2022/10/26 23:41:49 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -353,6 +353,34 @@ sysctl_kern_tty_setup(void) CTL_CREATE, CTL_EOL); } +/* + * ttylock(tp), ttyunlock(tp), ttylocked(tp) + * + * Exclusive lock on tty. Currently a single global lock. + * + * ttylocked is for positive DIAGNOSTIC assertions only. + */ +void +ttylock(struct tty *tp) +{ + + mutex_spin_enter(&tty_lock); +} + +void +ttyunlock(struct tty *tp) +{ + + mutex_spin_exit(&tty_lock); +} + +bool +ttylocked(struct tty *tp) +{ + + return mutex_owned(&tty_lock); +} + int ttyopen(struct tty *tp, int dialout, int nonblock) { Index: src/sys/sys/tty.h diff -u src/sys/sys/tty.h:1.102 src/sys/sys/tty.h:1.103 --- src/sys/sys/tty.h:1.102 Tue Oct 25 23:21:13 2022 +++ src/sys/sys/tty.h Wed Oct 26 23:41:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.102 2022/10/25 23:21:13 riastradh Exp $ */ +/* $NetBSD: tty.h,v 1.103 2022/10/26 23:41:49 riastradh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -319,6 +319,10 @@ int tty_unit(dev_t); void tty_acquire(struct tty *); void tty_release(struct tty *); +void ttylock(struct tty *); +void ttyunlock(struct tty *); +bool ttylocked(struct tty *); + int clalloc(struct clist *, int, int); void clfree(struct clist *);