kern_lockf.c (144278) | kern_lockf.c (170307) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Scooter Morris at Genentech Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)ufs_lockf.c 8.3 (Berkeley) 1/6/94 33 */ 34 35#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Scooter Morris at Genentech Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)ufs_lockf.c 8.3 (Berkeley) 1/6/94 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/kern/kern_lockf.c 144278 2005-03-29 08:13:01Z phk $"); | 36__FBSDID("$FreeBSD: head/sys/kern/kern_lockf.c 170307 2007-06-05 00:00:57Z jeff $"); |
37 38#include "opt_debug_lockf.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/limits.h> 44#include <sys/lock.h> --- 216 unchanged lines hidden (view full) --- 261 * 262 * Deadlock detection is done by looking through the 263 * wait channels to see if there are any cycles that 264 * involve us. MAXDEPTH is set just to make sure we 265 * do not go off into neverland. 266 */ 267 if ((lock->lf_flags & F_POSIX) && 268 (block->lf_flags & F_POSIX)) { | 37 38#include "opt_debug_lockf.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/limits.h> 44#include <sys/lock.h> --- 216 unchanged lines hidden (view full) --- 261 * 262 * Deadlock detection is done by looking through the 263 * wait channels to see if there are any cycles that 264 * involve us. MAXDEPTH is set just to make sure we 265 * do not go off into neverland. 266 */ 267 if ((lock->lf_flags & F_POSIX) && 268 (block->lf_flags & F_POSIX)) { |
269 register struct proc *wproc; | 269 struct proc *wproc; 270 struct proc *nproc; |
270 struct thread *td; | 271 struct thread *td; |
271 register struct lockf *waitblock; | 272 struct lockf *waitblock; |
272 int i = 0; 273 274 /* The block is waiting on something */ | 273 int i = 0; 274 275 /* The block is waiting on something */ |
275 /* XXXKSE this is not complete under threads */ | |
276 wproc = (struct proc *)block->lf_id; | 276 wproc = (struct proc *)block->lf_id; |
277 mtx_lock_spin(&sched_lock); | 277restart: 278 nproc = NULL; 279 PROC_SLOCK(wproc); |
278 FOREACH_THREAD_IN_PROC(wproc, td) { | 280 FOREACH_THREAD_IN_PROC(wproc, td) { |
281 thread_lock(td); |
|
279 while (td->td_wchan && 280 (td->td_wmesg == lockstr) && 281 (i++ < maxlockdepth)) { 282 waitblock = (struct lockf *)td->td_wchan; 283 /* Get the owner of the blocking lock */ 284 waitblock = waitblock->lf_next; 285 if ((waitblock->lf_flags & F_POSIX) == 0) 286 break; | 282 while (td->td_wchan && 283 (td->td_wmesg == lockstr) && 284 (i++ < maxlockdepth)) { 285 waitblock = (struct lockf *)td->td_wchan; 286 /* Get the owner of the blocking lock */ 287 waitblock = waitblock->lf_next; 288 if ((waitblock->lf_flags & F_POSIX) == 0) 289 break; |
287 wproc = (struct proc *)waitblock->lf_id; 288 if (wproc == (struct proc *)lock->lf_id) { 289 mtx_unlock_spin(&sched_lock); | 290 nproc = (struct proc *)waitblock->lf_id; 291 if (nproc == (struct proc *)lock->lf_id) { 292 PROC_SUNLOCK(wproc); 293 thread_unlock(td); |
290 free(lock, M_LOCKF); 291 return (EDEADLK); 292 } 293 } | 294 free(lock, M_LOCKF); 295 return (EDEADLK); 296 } 297 } |
298 thread_unlock(td); |
|
294 } | 299 } |
295 mtx_unlock_spin(&sched_lock); | 300 PROC_SUNLOCK(wproc); 301 wproc = nproc; 302 if (wproc) 303 goto restart; |
296 } 297 /* 298 * For flock type locks, we must first remove 299 * any shared locks that we hold before we sleep 300 * waiting for an exclusive lock. 301 */ 302 if ((lock->lf_flags & F_FLOCK) && 303 lock->lf_type == F_WRLCK) { --- 557 unchanged lines hidden --- | 304 } 305 /* 306 * For flock type locks, we must first remove 307 * any shared locks that we hold before we sleep 308 * waiting for an exclusive lock. 309 */ 310 if ((lock->lf_flags & F_FLOCK) && 311 lock->lf_type == F_WRLCK) { --- 557 unchanged lines hidden --- |