svn commit: r254209 - projects/camlock/sys/cam

Alexander Motin mav at FreeBSD.org
Sun Aug 11 08:08:23 UTC 2013


Author: mav
Date: Sun Aug 11 08:08:23 2013
New Revision: 254209
URL: http://svnweb.freebsd.org/changeset/base/254209

Log:
  In addition to r254143 allow cam_sim_hold/release() to be called unrelated
  to holding SIM lock.  If lock is not held, just take it inside.

Modified:
  projects/camlock/sys/cam/cam_sim.c

Modified: projects/camlock/sys/cam/cam_sim.c
==============================================================================
--- projects/camlock/sys/cam/cam_sim.c	Sun Aug 11 07:00:43 2013	(r254208)
+++ projects/camlock/sys/cam/cam_sim.c	Sun Aug 11 08:08:23 2013	(r254209)
@@ -124,21 +124,31 @@ cam_sim_free(struct cam_sim *sim, int fr
 void
 cam_sim_release(struct cam_sim *sim)
 {
-	KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
-	mtx_assert(sim->mtx, MA_OWNED);
+	int lock;
 
+	lock = (mtx_owned(sim->mtx) == 0);
+	if (lock)
+		CAM_SIM_LOCK(sim);
+	KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
 	sim->refcount--;
 	if (sim->refcount == 0)
 		wakeup(sim);
+	if (lock)
+		CAM_SIM_UNLOCK(sim);
 }
 
 void
 cam_sim_hold(struct cam_sim *sim)
 {
-	KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
-	mtx_assert(sim->mtx, MA_OWNED);
+	int lock;
 
+	lock = (mtx_owned(sim->mtx) == 0);
+	if (lock)
+		CAM_SIM_LOCK(sim);
+	KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
 	sim->refcount++;
+	if (lock)
+		CAM_SIM_UNLOCK(sim);
 }
 
 void


More information about the svn-src-projects mailing list