Deleted Added
sdiff udiff text old ( 104245 ) new ( 104306 )
full compact
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 $
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
148 * use the signal queue.
149 */
150 PROC_LOCK(p);
151 if ((p->p_flag & P_KTHREAD) == 0) {
152 PROC_UNLOCK(p);
153 return (EINVAL);
154 }
155 signal_add(p, NULL, SIGSTOP);
156 wakeup(p);
157 return msleep(&p->p_sigq, &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 }
172 signal_delete(p, NULL, SIGSTOP);
173 PROC_UNLOCK(p);
174 wakeup(&p->p_sigq);
175 return (0);
176}
177
178void
179kthread_suspend_check(struct proc *p)
180{
181 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);
185 }
186 PROC_UNLOCK(p);
187}