PERFORCE change 134244 for review

Kris Kennaway kris at FreeBSD.org
Wed Jan 30 12:42:48 PST 2008


John Birrell wrote:
> http://perforce.freebsd.org/chv.cgi?CH=134244
> 
> Change 134244 by jb at jb_freebsd1 on 2008/01/27 21:45:22
> 
> 	It seems I need an sx lock to be able to check if it locked.

Not sure what you mean by this.  All types of locks can check whether 
they are already held ("locked").

> 	It's an internal lock here, so the lock consistency is determined
> 	by the code in this file only.
> 	
> 	Specify SX_NOWITNESS to avoid the bogis LOR reports that WITNESS
> 	outputs when internal locks like this are obtained when there
> 	are various other locks already obtained. This lock has no bearing
> 	on the order that other locks are obtained.

It is assumed that if you are using an sx lock then your code may sleep 
while holding it (this is the property that distinguishes sx from rw 
locks).  However, if you sleep while holding a non-sleepable lock (e.g. 
mutex) then you can deadlock.  That is what witness correctly checks for.

If you know you will not be sleeping while holding your lock, use an 
rwlock instead of sx.

Kris


More information about the p4-projects mailing list