diff options
author | jhb <jhb@FreeBSD.org> | 2001-03-07 02:36:47 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2001-03-07 02:36:47 +0000 |
commit | d936d6d9be7bab125a42add7b5c3e4fbaa4a35d0 (patch) | |
tree | 9788e4e7b1c76df3bdf7cafcce953e6917ba7fc5 /sys/kern/kern_kthread.c | |
parent | 8dbcf4e47b467e6c555d7d4e81cc6ced6ae22f4d (diff) | |
download | FreeBSD-src-d936d6d9be7bab125a42add7b5c3e4fbaa4a35d0.zip FreeBSD-src-d936d6d9be7bab125a42add7b5c3e4fbaa4a35d0.tar.gz |
- Use _PHOLD and move it before a PROC_UNLOCK to reduce the number of
mutex operations in kthread_create().
- Lock a kthread's proc before changing its parent via proc_reparent().
- Test P_KTHREAD not P_SYSTEM in kthread_suspend() and kthread_resume().
P_SYSTEM just means that the process shouldn't be swapped and is used
for vinum's daemon for example.
- Lock all the signal state used for suspending and resuming kthreads with
the proc lock.
Diffstat (limited to 'sys/kern/kern_kthread.c')
-rw-r--r-- | sys/kern/kern_kthread.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index b322bc1..8dd9cd4 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -91,8 +91,8 @@ kthread_create(void (*func)(void *), void *arg, PROC_LOCK(p2); p2->p_flag |= P_SYSTEM | P_KTHREAD; p2->p_procsig->ps_flag |= PS_NOCLDWAIT; + _PHOLD(p2); PROC_UNLOCK(p2); - PHOLD(p2); /* set up arg0 for 'ps', et al */ va_start(ap, fmt); @@ -119,7 +119,9 @@ kthread_exit(int ecode) { PROCTREE_LOCK(PT_EXCLUSIVE); + PROC_LOCK(curproc); proc_reparent(curproc, initproc); + PROC_UNLOCK(curproc); PROCTREE_LOCK(PT_RELEASE); exit1(curproc, W_EXITCODE(ecode, 0)); } @@ -135,10 +137,13 @@ kthread_suspend(struct proc *p, int timo) * Make sure this is indeed a system process and we can safely * use the p_siglist field. */ - if ((p->p_flag & P_SYSTEM) == 0) + PROC_LOCK(p); + if ((p->p_flag & P_KTHREAD) == 0) { + PROC_UNLOCK(p); return (EINVAL); + } SIGADDSET(p->p_siglist, SIGSTOP); - return tsleep((caddr_t)&p->p_siglist, PPAUSE, "suspkt", timo); + return msleep(&p->p_siglist, &p->p_mtx, PPAUSE | PDROP, "suspkt", timo); } int @@ -148,18 +153,24 @@ kthread_resume(struct proc *p) * Make sure this is indeed a system process and we can safely * use the p_siglist field. */ - if ((p->p_flag & P_SYSTEM) == 0) + PROC_LOCK(p); + if ((p->p_flag & P_KTHREAD) == 0) { + PROC_UNLOCK(p); return (EINVAL); + } SIGDELSET(p->p_siglist, SIGSTOP); - wakeup((caddr_t)&p->p_siglist); + PROC_UNLOCK(p); + wakeup(&p->p_siglist); return (0); } void kthread_suspend_check(struct proc *p) { + PROC_LOCK(p); while (SIGISMEMBER(p->p_siglist, SIGSTOP)) { - wakeup((caddr_t)&p->p_siglist); - tsleep((caddr_t)&p->p_siglist, PPAUSE, "ktsusp", 0); + wakeup(&p->p_siglist); + msleep(&p->p_siglist, &p->p_mtx, PPAUSE, "ktsusp", 0); } + PROC_UNLOCK(p); } |