
Property changes on: sys
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys:r177843,178147


Property changes on: sys/conf
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/conf:r177843,178147


Property changes on: sys/kern
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/kern:r177843,178147

Index: sys/kern/kern_rwlock.c
===================================================================
--- sys/kern/kern_rwlock.c	(revision 181396)
+++ sys/kern/kern_rwlock.c	(working copy)
@@ -194,6 +194,30 @@
 	curthread->td_locks++;
 }
 
+int
+_rw_try_wlock(struct rwlock *rw, const char *file, int line)
+{
+	int rval;
+
+	KASSERT(rw->rw_lock != RW_DESTROYED,
+	    ("rw_try_wlock() of destroyed rwlock @ %s:%d", file, line));
+
+	if (rw_wlocked(rw) && (rw->lock_object.lo_flags & RW_RECURSE) != 0) {
+		rw->rw_recurse++;
+		rval = 1;
+	} else
+		rval = atomic_cmpset_acq_ptr(&rw->rw_lock, RW_UNLOCKED,
+		    (uintptr_t)curthread);
+
+	LOCK_LOG_TRY("WLOCK", &rw->lock_object, 0, rval, file, line);
+	if (rval) {
+		WITNESS_LOCK(&rw->lock_object, LOP_EXCLUSIVE | LOP_TRYLOCK,
+		    file, line);
+		curthread->td_locks++;
+	}
+	return (rval);
+}
+
 void
 _rw_wunlock(struct rwlock *rw, const char *file, int line)
 {
@@ -381,6 +405,30 @@
 	curthread->td_locks++;
 }
 
+int
+_rw_try_rlock(struct rwlock *rw, const char *file, int line)
+{
+	uintptr_t x;
+
+	for (;;) {
+		x = rw->rw_lock;
+		KASSERT(rw->rw_lock != RW_DESTROYED,
+		    ("rw_try_rlock() of destroyed rwlock @ %s:%d", file, line));
+		if (!(x & RW_LOCK_READ))
+			break;
+		if (atomic_cmpset_acq_ptr(&rw->rw_lock, x, x + RW_ONE_READER)) {
+			LOCK_LOG_TRY("RLOCK", &rw->lock_object, 0, 1, file,
+			    line);
+			WITNESS_LOCK(&rw->lock_object, LOP_TRYLOCK, file, line);
+			curthread->td_locks++;
+			return (1);
+		}
+	}
+
+	LOCK_LOG_TRY("RLOCK", &rw->lock_object, 0, 0, file, line);
+	return (0);
+}
+
 void
 _rw_runlock(struct rwlock *rw, const char *file, int line)
 {

Property changes on: sys/cam/scsi
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/cam/scsi:r177843,178147


Property changes on: sys/pci
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/pci:r177843,178147


Property changes on: sys/dev/gem
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/dev/gem:r177843,178147


Property changes on: sys/dev/cxgb
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/dev/cxgb:r177843,178147


Property changes on: sys/dev/usb
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/dev/usb:r177843,178147


Property changes on: sys/net/if_gre.c
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/net/if_gre.c:r177843,178147


Property changes on: sys/security/audit
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /head/sys/security/audit:r177843,178147

Index: sys/sys/rwlock.h
===================================================================
--- sys/sys/rwlock.h	(revision 181396)
+++ sys/sys/rwlock.h	(working copy)
@@ -129,8 +129,10 @@
 void	rw_sysinit(void *arg);
 int	rw_wowned(struct rwlock *rw);
 void	_rw_wlock(struct rwlock *rw, const char *file, int line);
+int	_rw_try_wlock(struct rwlock *rw, const char *file, int line);
 void	_rw_wunlock(struct rwlock *rw, const char *file, int line);
 void	_rw_rlock(struct rwlock *rw, const char *file, int line);
+int	_rw_try_rlock(struct rwlock *rw, const char *file, int line);
 void	_rw_runlock(struct rwlock *rw, const char *file, int line);
 void	_rw_wlock_hard(struct rwlock *rw, uintptr_t tid, const char *file,
 	    int line);
@@ -144,8 +146,6 @@
 
 /*
  * Public interface for lock operations.
- *
- * XXX: Missing try locks.
  */
 
 #ifndef LOCK_DEBUG
@@ -162,7 +162,9 @@
 #endif
 #define	rw_rlock(rw)		_rw_rlock((rw), LOCK_FILE, LOCK_LINE)
 #define	rw_runlock(rw)		_rw_runlock((rw), LOCK_FILE, LOCK_LINE)
+#define	rw_try_rlock(rw)	_rw_try_rlock((rw), LOCK_FILE, LOCK_LINE)
 #define	rw_try_upgrade(rw)	_rw_try_upgrade((rw), LOCK_FILE, LOCK_LINE)
+#define	rw_try_wlock(rw)	_rw_try_wlock((rw), LOCK_FILE, LOCK_LINE)
 #define	rw_downgrade(rw)	_rw_downgrade((rw), LOCK_FILE, LOCK_LINE)
 #define	rw_sleep(chan, rw, pri, wmesg, timo)				\
 	_sleep((chan), &(rw)->lock_object, (pri), (wmesg), (timo))
