diff options
author | Robert Watson <rwatson@FreeBSD.org> | 2005-09-26 08:02:24 +0000 |
---|---|---|
committer | Robert Watson <rwatson@FreeBSD.org> | 2005-09-26 08:02:24 +0000 |
commit | 329c75a73044af0f5a628267c024628cd4a609c3 (patch) | |
tree | 1e2342e36c143f3ce124a74aae5fa0bf47adafef /sys/kern | |
parent | 3d8d9f8f2dce3fdb7ba2c9d3e5cc548297e8fa3a (diff) | |
download | src-329c75a73044af0f5a628267c024628cd4a609c3.tar.gz src-329c75a73044af0f5a628267c024628cd4a609c3.zip |
Acquire Giant in uprintf() and tprintf() rather than asserting it. In
the vast majority of cases, these functions are called without mutexes
held, meaning that in all but two cases, there will be no ordering
issues with doing this, and it will eliminate the need for changes in
the caller. In two cases, mutexes are held, so Giant must be acquired
before those mutexes such that uprintf() and tprintf() recurse Giant
rather than generating a lock order reversal.
Suggested by: bde
Notes
Notes:
svn path=/head/; revision=150560
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/subr_prf.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 04bdb6d71de2..8184c01c9766 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -127,27 +127,31 @@ uprintf(const char *fmt, ...) struct putchar_arg pca; int retval; - GIANT_REQUIRED; if (td == NULL || td == PCPU_GET(idlethread)) return (0); + mtx_lock(&Giant); p = td->td_proc; PROC_LOCK(p); if ((p->p_flag & P_CONTROLT) == 0) { PROC_UNLOCK(p); - return (0); + retval = 0; + goto out; } SESS_LOCK(p->p_session); pca.tty = p->p_session->s_ttyp; SESS_UNLOCK(p->p_session); PROC_UNLOCK(p); - if (pca.tty == NULL) - return (0); + if (pca.tty == NULL) { + retval = 0; + goto out; + } pca.flags = TOTTY; va_start(ap, fmt); retval = kvprintf(fmt, putchar, &pca, 10, ap); va_end(ap); - +out: + mtx_unlock(&Giant); return (retval); } @@ -164,7 +168,7 @@ tprintf(struct proc *p, int pri, const char *fmt, ...) struct putchar_arg pca; struct session *sess = NULL; - GIANT_REQUIRED; + mtx_lock(&Giant); if (pri != -1) flags |= TOLOG; if (p != NULL) { @@ -192,6 +196,7 @@ tprintf(struct proc *p, int pri, const char *fmt, ...) if (sess != NULL) SESSRELE(sess); msgbuftrigger = 1; + mtx_unlock(&Giant); } /* |