Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys tty(9): New ttylock, ttyunlock, ttylocked functions.



details:   https://anonhg.NetBSD.org/src/rev/11d5dde04143
branches:  trunk
changeset: 372082:11d5dde04143
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Oct 26 23:41:49 2022 +0000

description:
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.

diffstat:

 sys/kern/tty.c |  32 ++++++++++++++++++++++++++++++--
 sys/sys/tty.h  |   6 +++++-
 2 files changed, 35 insertions(+), 3 deletions(-)

diffs (73 lines):

diff -r 3683125eb6d8 -r 11d5dde04143 sys/kern/tty.c
--- a/sys/kern/tty.c    Wed Oct 26 23:40:30 2022 +0000
+++ b/sys/kern/tty.c    Wed Oct 26 23:41:49 2022 +0000
@@ -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 @@
                       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)
 {
diff -r 3683125eb6d8 -r 11d5dde04143 sys/sys/tty.h
--- a/sys/sys/tty.h     Wed Oct 26 23:40:30 2022 +0000
+++ b/sys/sys/tty.h     Wed Oct 26 23:41:49 2022 +0000
@@ -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 @@
 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 *);
 



Home | Main Index | Thread Index | Old Index