Deleted Added
full compact
kern_synch.c (133396) kern_synch.c (134013)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 21 unchanged lines hidden (view full) ---

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95
35 */
36
37#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 21 unchanged lines hidden (view full) ---

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/kern_synch.c 133396 2004-08-09 18:21:12Z julian $");
38__FBSDID("$FreeBSD: head/sys/kern/kern_synch.c 134013 2004-08-19 11:31:42Z jhb $");
39
40#include "opt_ktrace.h"
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/condvar.h>
45#include <sys/kdb.h>
46#include <sys/kernel.h>

--- 73 unchanged lines hidden (view full) ---

120 void *ident;
121 struct mtx *mtx;
122 int priority, timo;
123 const char *wmesg;
124{
125 struct sleepqueue *sq;
126 struct thread *td;
127 struct proc *p;
39
40#include "opt_ktrace.h"
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/condvar.h>
45#include <sys/kdb.h>
46#include <sys/kernel.h>

--- 73 unchanged lines hidden (view full) ---

120 void *ident;
121 struct mtx *mtx;
122 int priority, timo;
123 const char *wmesg;
124{
125 struct sleepqueue *sq;
126 struct thread *td;
127 struct proc *p;
128 int catch, rval, sig;
128 int catch, rval, sig, flags;
129 WITNESS_SAVE_DECL(mtx);
130
131 td = curthread;
132 p = td->td_proc;
133#ifdef KTRACE
134 if (KTRPOINT(td, KTR_CSW))
135 ktrcsw(1, 0);
136#endif

--- 24 unchanged lines hidden (view full) ---

161 * If we are already on a sleep queue, then remove us from that
162 * sleep queue first. We have to do this to handle recursive
163 * sleeps.
164 */
165 if (TD_ON_SLEEPQ(td))
166 sleepq_remove(td, td->td_wchan);
167
168 sq = sleepq_lookup(ident);
129 WITNESS_SAVE_DECL(mtx);
130
131 td = curthread;
132 p = td->td_proc;
133#ifdef KTRACE
134 if (KTRPOINT(td, KTR_CSW))
135 ktrcsw(1, 0);
136#endif

--- 24 unchanged lines hidden (view full) ---

161 * If we are already on a sleep queue, then remove us from that
162 * sleep queue first. We have to do this to handle recursive
163 * sleeps.
164 */
165 if (TD_ON_SLEEPQ(td))
166 sleepq_remove(td, td->td_wchan);
167
168 sq = sleepq_lookup(ident);
169 mtx_lock_spin(&sched_lock);
170
171 if (p->p_flag & P_SA || p->p_numthreads > 1) {
169 if (catch) {
172 /*
170 /*
173 * Just don't bother if we are exiting
174 * and not the exiting thread or thread was marked as
175 * interrupted.
171 * Don't bother sleeping if we are exiting and not the exiting
172 * thread or if our thread is marked as interrupted.
176 */
173 */
177 if (catch) {
178 if ((p->p_flag & P_SINGLE_EXIT) && p->p_singlethread != td) {
179 mtx_unlock_spin(&sched_lock);
180 sleepq_release(ident);
181 return (EINTR);
182 }
183 if (td->td_flags & TDF_INTERRUPT) {
184 mtx_unlock_spin(&sched_lock);
185 sleepq_release(ident);
186 return (td->td_intrval);
187 }
174 mtx_lock_spin(&sched_lock);
175 rval = thread_sleep_check(td);
176 mtx_unlock_spin(&sched_lock);
177 if (rval != 0) {
178 sleepq_release(ident);
179 return (rval);
188 }
189 }
180 }
181 }
190 mtx_unlock_spin(&sched_lock);
191 CTR5(KTR_PROC, "msleep: thread %p (pid %ld, %s) on %s (%p)",
192 (void *)td, (long)p->p_pid, p->p_comm, wmesg, ident);
193
194 DROP_GIANT();
195 if (mtx != NULL) {
196 mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED);
197 WITNESS_SAVE(&mtx->mtx_object, mtx);
198 mtx_unlock(mtx);
199 }
200
201 /*
202 * We put ourselves on the sleep queue and start our timeout
203 * before calling thread_suspend_check, as we could stop there,
204 * and a wakeup or a SIGCONT (or both) could occur while we were
205 * stopped without resuming us. Thus, we must be ready for sleep
206 * when cursig() is called. If the wakeup happens while we're
207 * stopped, then td will no longer be on a sleep queue upon
208 * return from cursig().
209 */
182 CTR5(KTR_PROC, "msleep: thread %p (pid %ld, %s) on %s (%p)",
183 (void *)td, (long)p->p_pid, p->p_comm, wmesg, ident);
184
185 DROP_GIANT();
186 if (mtx != NULL) {
187 mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED);
188 WITNESS_SAVE(&mtx->mtx_object, mtx);
189 mtx_unlock(mtx);
190 }
191
192 /*
193 * We put ourselves on the sleep queue and start our timeout
194 * before calling thread_suspend_check, as we could stop there,
195 * and a wakeup or a SIGCONT (or both) could occur while we were
196 * stopped without resuming us. Thus, we must be ready for sleep
197 * when cursig() is called. If the wakeup happens while we're
198 * stopped, then td will no longer be on a sleep queue upon
199 * return from cursig().
200 */
210 sleepq_add(sq, ident, mtx, wmesg, 0);
201 flags = SLEEPQ_MSLEEP;
202 if (catch)
203 flags |= SLEEPQ_INTERRUPTIBLE;
204 sleepq_add(sq, ident, mtx, wmesg, flags);
211 if (timo)
212 sleepq_set_timeout(ident, timo);
213 if (catch) {
214 sig = sleepq_catch_signals(ident);
205 if (timo)
206 sleepq_set_timeout(ident, timo);
207 if (catch) {
208 sig = sleepq_catch_signals(ident);
215 if (sig == 0 && !TD_ON_SLEEPQ(td)) {
216 mtx_lock_spin(&sched_lock);
217 td->td_flags &= ~TDF_SINTR;
218 mtx_unlock_spin(&sched_lock);
219 catch = 0;
220 }
221 } else
222 sig = 0;
223
224 /*
225 * Adjust this thread's priority.
226 *
227 * XXX: do we need to save priority in td_base_pri?
228 */

--- 28 unchanged lines hidden (view full) ---

257/*
258 * Make all threads sleeping on the specified identifier runnable.
259 */
260void
261wakeup(ident)
262 register void *ident;
263{
264
209 } else
210 sig = 0;
211
212 /*
213 * Adjust this thread's priority.
214 *
215 * XXX: do we need to save priority in td_base_pri?
216 */

--- 28 unchanged lines hidden (view full) ---

245/*
246 * Make all threads sleeping on the specified identifier runnable.
247 */
248void
249wakeup(ident)
250 register void *ident;
251{
252
265 sleepq_broadcast(ident, 0, -1);
253 sleepq_broadcast(ident, SLEEPQ_MSLEEP, -1);
266}
267
268/*
269 * Make a thread sleeping on the specified identifier runnable.
270 * May wake more than one thread if a target thread is currently
271 * swapped out.
272 */
273void
274wakeup_one(ident)
275 register void *ident;
276{
277
254}
255
256/*
257 * Make a thread sleeping on the specified identifier runnable.
258 * May wake more than one thread if a target thread is currently
259 * swapped out.
260 */
261void
262wakeup_one(ident)
263 register void *ident;
264{
265
278 sleepq_signal(ident, 0, -1);
266 sleepq_signal(ident, SLEEPQ_MSLEEP, -1);
279}
280
281/*
282 * The machine independent parts of context switching.
283 */
284void
285mi_switch(int flags, struct thread *newtd)
286{

--- 195 unchanged lines hidden ---
267}
268
269/*
270 * The machine independent parts of context switching.
271 */
272void
273mi_switch(int flags, struct thread *newtd)
274{

--- 195 unchanged lines hidden ---