kern_kthread.c (104245) | kern_kthread.c (104306) |
---|---|
1/* 2 * Copyright (c) 1999 Peter Wemm <peter@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 1999 Peter Wemm <peter@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/kern_kthread.c 104233 2002-09-30 20:20:22Z jmallett $ | 26 * $FreeBSD: head/sys/kern/kern_kthread.c 104306 2002-10-01 17:15:53Z jmallett $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kthread.h> 32#include <sys/lock.h> 33#include <sys/mutex.h> 34#include <sys/proc.h> 35#include <sys/resourcevar.h> 36#include <sys/signalvar.h> 37#include <sys/sx.h> 38#include <sys/unistd.h> 39#include <sys/wait.h> | 27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kthread.h> 32#include <sys/lock.h> 33#include <sys/mutex.h> 34#include <sys/proc.h> 35#include <sys/resourcevar.h> 36#include <sys/signalvar.h> 37#include <sys/sx.h> 38#include <sys/unistd.h> 39#include <sys/wait.h> |
40#include <sys/ksiginfo.h> | |
41 42#include <machine/stdarg.h> 43 44/* 45 * Start a kernel process. This is called after a fork() call in 46 * mi_startup() in the file kern/init_main.c. 47 * 48 * This function is used to start "internal" daemons and intended --- 91 unchanged lines hidden (view full) --- 140 * Advise a kernel process to suspend (or resume) in its main loop. 141 * Participation is voluntary. 142 */ 143int 144kthread_suspend(struct proc *p, int timo) 145{ 146 /* 147 * Make sure this is indeed a system process and we can safely | 40 41#include <machine/stdarg.h> 42 43/* 44 * Start a kernel process. This is called after a fork() call in 45 * mi_startup() in the file kern/init_main.c. 46 * 47 * This function is used to start "internal" daemons and intended --- 91 unchanged lines hidden (view full) --- 139 * Advise a kernel process to suspend (or resume) in its main loop. 140 * Participation is voluntary. 141 */ 142int 143kthread_suspend(struct proc *p, int timo) 144{ 145 /* 146 * Make sure this is indeed a system process and we can safely |
148 * use the signal queue. | 147 * use the p_siglist field. |
149 */ 150 PROC_LOCK(p); 151 if ((p->p_flag & P_KTHREAD) == 0) { 152 PROC_UNLOCK(p); 153 return (EINVAL); 154 } | 148 */ 149 PROC_LOCK(p); 150 if ((p->p_flag & P_KTHREAD) == 0) { 151 PROC_UNLOCK(p); 152 return (EINVAL); 153 } |
155 signal_add(p, NULL, SIGSTOP); | 154 SIGADDSET(p->p_siglist, SIGSTOP); |
156 wakeup(p); | 155 wakeup(p); |
157 return msleep(&p->p_sigq, &p->p_mtx, PPAUSE | PDROP, "suspkt", timo); | 156 return msleep(&p->p_siglist, &p->p_mtx, PPAUSE | PDROP, "suspkt", timo); |
158} 159 160int 161kthread_resume(struct proc *p) 162{ 163 /* 164 * Make sure this is indeed a system process and we can safely 165 * use the p_siglist field. 166 */ 167 PROC_LOCK(p); 168 if ((p->p_flag & P_KTHREAD) == 0) { 169 PROC_UNLOCK(p); 170 return (EINVAL); 171 } | 157} 158 159int 160kthread_resume(struct proc *p) 161{ 162 /* 163 * Make sure this is indeed a system process and we can safely 164 * use the p_siglist field. 165 */ 166 PROC_LOCK(p); 167 if ((p->p_flag & P_KTHREAD) == 0) { 168 PROC_UNLOCK(p); 169 return (EINVAL); 170 } |
172 signal_delete(p, NULL, SIGSTOP); | 171 SIGDELSET(p->p_siglist, SIGSTOP); |
173 PROC_UNLOCK(p); | 172 PROC_UNLOCK(p); |
174 wakeup(&p->p_sigq); | 173 wakeup(&p->p_siglist); |
175 return (0); 176} 177 178void 179kthread_suspend_check(struct proc *p) 180{ 181 PROC_LOCK(p); | 174 return (0); 175} 176 177void 178kthread_suspend_check(struct proc *p) 179{ 180 PROC_LOCK(p); |
182 while (signal_queued(p, SIGSTOP)) { 183 wakeup(&p->p_sigq); 184 msleep(&p->p_sigq, &p->p_mtx, PPAUSE, "ktsusp", 0); | 181 while (SIGISMEMBER(p->p_siglist, SIGSTOP)) { 182 wakeup(&p->p_siglist); 183 msleep(&p->p_siglist, &p->p_mtx, PPAUSE, "ktsusp", 0); |
185 } 186 PROC_UNLOCK(p); 187} | 184 } 185 PROC_UNLOCK(p); 186} |