Deleted Added
full compact
kern_lock.c (71576) kern_lock.c (72200)
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Copyright (C) 1997
6 * John S. Dyson. All rights reserved.
7 *
8 * This code contains ideas from software contributed to Berkeley by

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

33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)kern_lock.c 8.18 (Berkeley) 5/21/95
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Copyright (C) 1997
6 * John S. Dyson. All rights reserved.
7 *
8 * This code contains ideas from software contributed to Berkeley by

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

33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)kern_lock.c 8.18 (Berkeley) 5/21/95
41 * $FreeBSD: head/sys/kern/kern_lock.c 71576 2001-01-24 12:35:55Z jasone $
41 * $FreeBSD: head/sys/kern/kern_lock.c 72200 2001-02-09 06:11:45Z bmilekic $
42 */
43
44#include <sys/param.h>
45#include <sys/proc.h>
46#include <sys/kernel.h>
47#include <sys/lock.h>
48#include <sys/malloc.h>
49#include <sys/mutex.h>

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

139#ifdef SMP
140 int i, lock_wait;
141#endif
142
143 if ((lkp->lk_flags & flags) == 0)
144 return 0;
145#ifdef SMP
146 for (lock_wait = LOCK_WAIT_TIME; lock_wait > 0; lock_wait--) {
42 */
43
44#include <sys/param.h>
45#include <sys/proc.h>
46#include <sys/kernel.h>
47#include <sys/lock.h>
48#include <sys/malloc.h>
49#include <sys/mutex.h>

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

139#ifdef SMP
140 int i, lock_wait;
141#endif
142
143 if ((lkp->lk_flags & flags) == 0)
144 return 0;
145#ifdef SMP
146 for (lock_wait = LOCK_WAIT_TIME; lock_wait > 0; lock_wait--) {
147 mtx_exit(lkp->lk_interlock, MTX_DEF);
147 mtx_unlock(lkp->lk_interlock);
148 for (i = LOCK_SAMPLE_WAIT; i > 0; i--)
149 if ((lkp->lk_flags & flags) == 0)
150 break;
148 for (i = LOCK_SAMPLE_WAIT; i > 0; i--)
149 if ((lkp->lk_flags & flags) == 0)
150 break;
151 mtx_enter(lkp->lk_interlock, MTX_DEF);
151 mtx_lock(lkp->lk_interlock);
152 if ((lkp->lk_flags & flags) == 0)
153 return 0;
154 }
155#endif
156 return 1;
157}
158
159static int

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

231 "interlkp == %p, p == %p", lkp, lkp->lk_wmesg, flags, interlkp, p);
232
233 error = 0;
234 if (p == NULL)
235 pid = LK_KERNPROC;
236 else
237 pid = p->p_pid;
238
152 if ((lkp->lk_flags & flags) == 0)
153 return 0;
154 }
155#endif
156 return 1;
157}
158
159static int

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

231 "interlkp == %p, p == %p", lkp, lkp->lk_wmesg, flags, interlkp, p);
232
233 error = 0;
234 if (p == NULL)
235 pid = LK_KERNPROC;
236 else
237 pid = p->p_pid;
238
239 mtx_enter(lkp->lk_interlock, MTX_DEF);
239 mtx_lock(lkp->lk_interlock);
240 if (flags & LK_INTERLOCK)
240 if (flags & LK_INTERLOCK)
241 mtx_exit(interlkp, MTX_DEF);
241 mtx_unlock(interlkp);
242
243 extflags = (flags | lkp->lk_flags) & LK_EXTFLG_MASK;
244
245 switch (flags & LK_TYPE_MASK) {
246
247 case LK_SHARED:
248 /*
249 * If we are not the exclusive lock holder, we have to block

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

446#if defined(DEBUG_LOCKS)
447 lkp->lk_filename = file;
448 lkp->lk_lineno = line;
449 lkp->lk_lockername = name;
450#endif
451 break;
452
453 default:
242
243 extflags = (flags | lkp->lk_flags) & LK_EXTFLG_MASK;
244
245 switch (flags & LK_TYPE_MASK) {
246
247 case LK_SHARED:
248 /*
249 * If we are not the exclusive lock holder, we have to block

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

446#if defined(DEBUG_LOCKS)
447 lkp->lk_filename = file;
448 lkp->lk_lineno = line;
449 lkp->lk_lockername = name;
450#endif
451 break;
452
453 default:
454 mtx_exit(lkp->lk_interlock, MTX_DEF);
454 mtx_unlock(lkp->lk_interlock);
455 panic("lockmgr: unknown locktype request %d",
456 flags & LK_TYPE_MASK);
457 /* NOTREACHED */
458 }
459 if ((lkp->lk_flags & LK_WAITDRAIN) &&
460 (lkp->lk_flags & (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE |
461 LK_SHARE_NONZERO | LK_WAIT_NONZERO)) == 0) {
462 lkp->lk_flags &= ~LK_WAITDRAIN;
463 wakeup((void *)&lkp->lk_flags);
464 }
455 panic("lockmgr: unknown locktype request %d",
456 flags & LK_TYPE_MASK);
457 /* NOTREACHED */
458 }
459 if ((lkp->lk_flags & LK_WAITDRAIN) &&
460 (lkp->lk_flags & (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE |
461 LK_SHARE_NONZERO | LK_WAIT_NONZERO)) == 0) {
462 lkp->lk_flags &= ~LK_WAITDRAIN;
463 wakeup((void *)&lkp->lk_flags);
464 }
465 mtx_exit(lkp->lk_interlock, MTX_DEF);
465 mtx_unlock(lkp->lk_interlock);
466 return (error);
467}
468
469static int
470acquiredrain(struct lock *lkp, int extflags) {
471 int error;
472
473 if ((extflags & LK_NOWAIT) && (lkp->lk_flags & LK_ALL)) {

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

501 char *wmesg;
502 int timo;
503 int flags;
504{
505 CTR5(KTR_LOCKMGR, "lockinit(): lkp == %p, prio == %d, wmesg == \"%s\", "
506 "timo == %d, flags = 0x%x\n", lkp, prio, wmesg, timo, flags);
507
508 if (lock_mtx_array != NULL) {
466 return (error);
467}
468
469static int
470acquiredrain(struct lock *lkp, int extflags) {
471 int error;
472
473 if ((extflags & LK_NOWAIT) && (lkp->lk_flags & LK_ALL)) {

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

501 char *wmesg;
502 int timo;
503 int flags;
504{
505 CTR5(KTR_LOCKMGR, "lockinit(): lkp == %p, prio == %d, wmesg == \"%s\", "
506 "timo == %d, flags = 0x%x\n", lkp, prio, wmesg, timo, flags);
507
508 if (lock_mtx_array != NULL) {
509 mtx_enter(&lock_mtx, MTX_DEF);
509 mtx_lock(&lock_mtx);
510 lkp->lk_interlock = &lock_mtx_array[lock_mtx_selector];
511 lock_mtx_selector++;
512 if (lock_mtx_selector == lock_nmtx)
513 lock_mtx_selector = 0;
510 lkp->lk_interlock = &lock_mtx_array[lock_mtx_selector];
511 lock_mtx_selector++;
512 if (lock_mtx_selector == lock_nmtx)
513 lock_mtx_selector = 0;
514 mtx_exit(&lock_mtx, MTX_DEF);
514 mtx_unlock(&lock_mtx);
515 } else {
516 /*
517 * Giving lockmgr locks that are initialized during boot a
518 * pointer to the internal lockmgr mutex is safe, since the
519 * lockmgr code itself doesn't call lockinit() (which could
520 * cause mutex recursion).
521 */
522 if (lock_mtx_selector == 0) {

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

556 */
557int
558lockstatus(lkp, p)
559 struct lock *lkp;
560 struct proc *p;
561{
562 int lock_type = 0;
563
515 } else {
516 /*
517 * Giving lockmgr locks that are initialized during boot a
518 * pointer to the internal lockmgr mutex is safe, since the
519 * lockmgr code itself doesn't call lockinit() (which could
520 * cause mutex recursion).
521 */
522 if (lock_mtx_selector == 0) {

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

556 */
557int
558lockstatus(lkp, p)
559 struct lock *lkp;
560 struct proc *p;
561{
562 int lock_type = 0;
563
564 mtx_enter(lkp->lk_interlock, MTX_DEF);
564 mtx_lock(lkp->lk_interlock);
565 if (lkp->lk_exclusivecount != 0) {
566 if (p == NULL || lkp->lk_lockholder == p->p_pid)
567 lock_type = LK_EXCLUSIVE;
568 else
569 lock_type = LK_EXCLOTHER;
570 } else if (lkp->lk_sharecount != 0)
571 lock_type = LK_SHARED;
565 if (lkp->lk_exclusivecount != 0) {
566 if (p == NULL || lkp->lk_lockholder == p->p_pid)
567 lock_type = LK_EXCLUSIVE;
568 else
569 lock_type = LK_EXCLOTHER;
570 } else if (lkp->lk_sharecount != 0)
571 lock_type = LK_SHARED;
572 mtx_exit(lkp->lk_interlock, MTX_DEF);
572 mtx_unlock(lkp->lk_interlock);
573 return (lock_type);
574}
575
576/*
577 * Determine the number of holders of a lock.
578 */
579int
580lockcount(lkp)
581 struct lock *lkp;
582{
583 int count;
584
573 return (lock_type);
574}
575
576/*
577 * Determine the number of holders of a lock.
578 */
579int
580lockcount(lkp)
581 struct lock *lkp;
582{
583 int count;
584
585 mtx_enter(lkp->lk_interlock, MTX_DEF);
585 mtx_lock(lkp->lk_interlock);
586 count = lkp->lk_exclusivecount + lkp->lk_sharecount;
586 count = lkp->lk_exclusivecount + lkp->lk_sharecount;
587 mtx_exit(lkp->lk_interlock, MTX_DEF);
587 mtx_unlock(lkp->lk_interlock);
588 return (count);
589}
590
591/*
592 * Print out information about state of a lock. Used by VOP_PRINT
593 * routines to display status about contained locks.
594 */
595void

--- 13 unchanged lines hidden ---
588 return (count);
589}
590
591/*
592 * Print out information about state of a lock. Used by VOP_PRINT
593 * routines to display status about contained locks.
594 */
595void

--- 13 unchanged lines hidden ---