Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Nov 1999 00:30:12 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Assar Westerlund <assar@sics.se>
Cc:        current@FreeBSD.ORG
Subject:   Re: inconsistent and wrong locking in asleep()
Message-ID:  <Pine.BSF.4.10.9911092359380.10910-100000@alphplex.bde.org>
In-Reply-To: <5l4sevrhxk.fsf@assaris.sics.se>

next in thread | previous in thread | raw e-mail | index | archive | help
> Why trying to debug some locking code of my own I enabled
> SIMPLELOCK_DEBUG, only to find out that I was getting lots of
> `simple_unlock: lock not held' in lockmgr -> acquire -> apause.
> 
> Looking closer at `apause' it seems rather clear that it can cause
> this.  I proposed simple change is below.

That's a really old bug.  I fixed it a year or two ago in my version,
and optimised the !SMP case following a suggestion of tegge (waiting
for the lock is useless in the !SMP case).

Bruce

diff -c2 kern_lock.c~ kern_lock.c
*** kern_lock.c~	Tue Sep 28 06:06:16 1999
--- kern_lock.c	Tue Sep 28 06:07:59 1999
***************
*** 104,125 ****
   */
  static int
! apause(struct lock *lkp, int flags) {
! 	int lock_wait;
! 	lock_wait = LOCK_WAIT_TIME;
! 	for (; lock_wait > 0; lock_wait--) {
! 		int i;
! 		if ((lkp->lk_flags & flags) == 0)
! 			return 0;
  		simple_unlock(&lkp->lk_interlock);
! 		for (i = LOCK_SAMPLE_WAIT; i > 0; i--) {
! 			if ((lkp->lk_flags & flags) == 0) {
! 				simple_lock(&lkp->lk_interlock);
! 				if ((lkp->lk_flags & flags) == 0)
! 					return 0;
  				break;
! 			}
! 		}
  	}
! 	return 1;
  }
  
--- 103,126 ----
   */
  static int
! apause(struct lock *lkp, int flags)
! {
! #ifdef SMP
! 	int i, lock_wait;
! #endif
! 	
! 	if ((lkp->lk_flags & flags) == 0)
! 		return (0);
! #ifdef SMP
! 	for (lock_wait = LOCK_WAIT_TIME; lock_wait > 0; lock_wait--) {
  		simple_unlock(&lkp->lk_interlock);
! 		for (i = LOCK_SAMPLE_WAIT; i > 0; i--)
! 			if ((lkp->lk_flags & flags) == 0)
  				break;
! 		simple_lock(&lkp->lk_interlock);
! 		if ((lkp->lk_flags & flags) == 0)
! 			return (0);
  	}
! #endif
! 	return (1);
  }
  



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.9911092359380.10910-100000>