Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jun 2006 03:54:39 GMT
From:      Kip Macy <kmacy@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 100183 for review
Message-ID:  <200606280354.k5S3sdtZ039391@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100183

Change 100183 by kmacy@kmacy_storage:sun4v_work_sleepq on 2006/06/28 03:54:19

	rename sx to sxu
	add condition variable for drain waiter

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/sxu.h#2 edit

Differences ...

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#3 (text+ko) ====

@@ -54,11 +54,11 @@
 #include <ddb/ddb.h>
 
 #ifdef DDB
-static void	db_show_sx(struct lock_object *lock);
+static void	db_show_sxu(struct lock_object *lock);
 #endif
 
-struct lock_class lock_class_sx = {
-	"sx",
+struct lock_class lock_class_sxu = {
+	"sxu",
 	LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE,
 #ifdef DDB
 	db_show_sx
@@ -66,52 +66,52 @@
 };
 
 #ifndef INVARIANTS
-#define	_sx_assert(sx, what, file, line)
+#define	_sxu_assert(sx, what, file, line)
 #endif
 
 void
-sx_sysinit(void *arg)
+sxu_sysinit(void *arg)
 {
-	struct sx_args *sargs = arg;
+	struct sxu_args *sargs = arg;
 
-	sx_init(sargs->sa_sx, sargs->sa_desc);
+	sxu_init(sargs->sa_sxu, sargs->sa_desc);
 }
 
 void
-sx_init(struct sx *sx, const char *description)
+sxu_init(struct sxu *sx, const char *description)
 {
 
-	sx->sx_lock = mtx_pool_find(mtxpool_lockbuilder, sx);
-	sx->sx_cnt = 0;
-	cv_init(&sx->sx_shrd_cv, description);
-	sx->sx_shrd_wcnt = 0;
-	cv_init(&sx->sx_excl_cv, description);
-	sx->sx_excl_wcnt = 0;
-	sx->sx_xholder = NULL;
+	sx->sxu_lock = mtx_pool_find(mtxpool_lockbuilder, sx);
+	sx->sxu_cnt = 0;
+	cv_init(&sx->sxu_shrd_cv, description);
+	sx->sxu_shrd_wcnt = 0;
+	cv_init(&sx->sxu_excl_cv, description);
+	sx->sxu_excl_wcnt = 0;
+	sx->sxu_xholder = NULL;
 
-	lock_profile_init(&sx->sx_object, description);
-	lock_init(&sx->sx_object, &lock_class_sx, description, NULL,
+	lock_profile_init(&sx->sxu_object, description);
+	lock_init(&sx->sxu_object, &lock_class_sxu, description, NULL,
 	    LO_WITNESS | LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE);
 }
 
 void
-sx_destroy(struct sx *sx)
+sxu_destroy(struct sxu *sx)
 {
 
-	KASSERT((sx->sx_cnt == 0 && sx->sx_shrd_wcnt == 0 && sx->sx_excl_wcnt ==
+	KASSERT((sx->sxu_cnt == 0 && sx->sxu_shrd_wcnt == 0 && sx->sxu_excl_wcnt ==
 	    0), ("%s (%s): holders or waiters\n", __func__,
-	    sx->sx_object.lo_name));
+	    sx->sxu_object.lo_name));
 
-	sx->sx_lock = NULL;
-	cv_destroy(&sx->sx_shrd_cv);
-	cv_destroy(&sx->sx_excl_cv);
+	sx->sxu_lock = NULL;
+	cv_destroy(&sx->sxu_shrd_cv);
+	cv_destroy(&sx->sxu_excl_cv);
 
-	lock_profile_destroy(&sx->sx_object);
-	lock_destroy(&sx->sx_object);
+	lock_profile_destroy(&sx->sxu_object);
+	lock_destroy(&sx->sxu_object);
 }
 
 int
-_sx_slock(struct sx *sx, int timo, const char *file, int line)
+_sxu_slock(struct sxu *sx, int timo, const char *file, int line)
 {
 
 	int contested, error;
@@ -120,64 +120,64 @@
 	waittime = 0;
 	error = 0;
 	
-	mtx_lock(sx->sx_lock);
-	KASSERT(sx->sx_xholder != curthread,
+	mtx_lock(sx->sxu_lock);
+	KASSERT(sx->sxu_xholder != curthread,
 	    ("%s (%s): slock while xlock is held @ %s:%d\n", __func__,
-	    sx->sx_object.lo_name, file, line));
-	WITNESS_CHECKORDER(&sx->sx_object, LOP_NEWORDER, file, line);
+	    sx->sxu_object.lo_name, file, line));
+	WITNESS_CHECKORDER(&sx->sxu_object, LOP_NEWORDER, file, line);
 
 	/*
 	 * Loop in case we lose the race for lock acquisition.
 	 */
-	if (sx->sx_cnt < 0)
+	if (sx->sxu_cnt < 0)
 		lock_profile_waitstart(&waittime);
-	while (sx->sx_cnt < 0) {
-		sx->sx_shrd_wcnt++;
-		lock_profile_obtain_lock_failed(&sx->sx_object, &contested);
+	while (sx->sxu_cnt < 0) {
+		sx->sxu_shrd_wcnt++;
+		lock_profile_obtain_lock_failed(&sx->sxu_object, &contested);
 		if (timo)
-			error = cv_timedwait(&sx->sx_shrd_cv, sx->sx_lock, timo);
+			error = cv_timedwait(&sx->sxu_shrd_cv, sx->sxu_lock, timo);
 		else
-			cv_wait(&sx->sx_shrd_cv, sx->sx_lock);
-		sx->sx_shrd_wcnt--;
+			cv_wait(&sx->sxu_shrd_cv, sx->sxu_lock);
+		sx->sxu_shrd_wcnt--;
 		if (error)
 			goto fail;
 	}
 
 
 	/* Acquire a shared lock. */
-	sx->sx_cnt++;
+	sx->sxu_cnt++;
 
-	if (sx->sx_cnt == 1)
-		lock_profile_obtain_lock_success(&sx->sx_object, waittime, file, line);
+	if (sx->sxu_cnt == 1)
+		lock_profile_obtain_lock_success(&sx->sxu_object, waittime, file, line);
 
-	LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line);
-	WITNESS_LOCK(&sx->sx_object, 0, file, line);
+	LOCK_LOG_LOCK("SLOCK", &sx->sxu_object, 0, 0, file, line);
+	WITNESS_LOCK(&sx->sxu_object, 0, file, line);
 
  fail:
-	mtx_unlock(sx->sx_lock);
+	mtx_unlock(sx->sxu_lock);
 	return (error);
 }
 
 int
-_sx_try_slock(struct sx *sx, const char *file, int line)
+_sxu_try_slock(struct sxu *sx, const char *file, int line)
 {
 
-	mtx_lock(sx->sx_lock);
-	if (sx->sx_cnt >= 0) {
-		sx->sx_cnt++;
-		LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 1, file, line);
-		WITNESS_LOCK(&sx->sx_object, LOP_TRYLOCK, file, line);
-		mtx_unlock(sx->sx_lock);
+	mtx_lock(sx->sxu_lock);
+	if (sx->sxu_cnt >= 0) {
+		sx->sxu_cnt++;
+		LOCK_LOG_TRY("SLOCK", &sx->sxu_object, 0, 1, file, line);
+		WITNESS_LOCK(&sx->sxu_object, LOP_TRYLOCK, file, line);
+		mtx_unlock(sx->sxu_lock);
 		return (1);
 	} else {
-		LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 0, file, line);
-		mtx_unlock(sx->sx_lock);
+		LOCK_LOG_TRY("SLOCK", &sx->sxu_object, 0, 0, file, line);
+		mtx_unlock(sx->sxu_lock);
 		return (0);
 	}
 }
 
 int
-_sx_xlock(struct sx *sx, int timo, const char *file, int line)
+_sxu_xlock(struct sxu *sx, int timo, const char *file, int line)
 {
 	
 	int contested, error;
@@ -186,7 +186,7 @@
 	error = 0;
 	waittime= 0;
 	
-	mtx_lock(sx->sx_lock);
+	mtx_lock(sx->sxu_lock);
 
 	/*
 	 * With sx locks, we're absolutely not permitted to recurse on
@@ -195,74 +195,74 @@
 	 * xlock while in here, we consider it API abuse and put it under
 	 * INVARIANTS.
 	 */
-	KASSERT(sx->sx_xholder != curthread,
+	KASSERT(sx->sxu_xholder != curthread,
 	    ("%s (%s): xlock already held @ %s:%d", __func__,
-	    sx->sx_object.lo_name, file, line));
-	WITNESS_CHECKORDER(&sx->sx_object, LOP_NEWORDER | LOP_EXCLUSIVE, file,
+	    sx->sxu_object.lo_name, file, line));
+	WITNESS_CHECKORDER(&sx->sxu_object, LOP_NEWORDER | LOP_EXCLUSIVE, file,
 	    line);
 
 	/* Loop in case we lose the race for lock acquisition. */
-	if (sx->sx_cnt)
+	if (sx->sxu_cnt)
 		lock_profile_waitstart(&waittime);
-	while (sx->sx_cnt != 0) {
-		sx->sx_excl_wcnt++;
-		lock_profile_obtain_lock_failed(&sx->sx_object, &contested);
+	while (sx->sxu_cnt != 0) {
+		sx->sxu_excl_wcnt++;
+		lock_profile_obtain_lock_failed(&sx->sxu_object, &contested);
 		if (timo)
-			error = cv_timedwait(&sx->sx_excl_cv, sx->sx_lock, timo);
+			error = cv_timedwait(&sx->sxu_excl_cv, sx->sxu_lock, timo);
 		else
-			cv_wait(&sx->sx_excl_cv, sx->sx_lock);
-		sx->sx_excl_wcnt--;
+			cv_wait(&sx->sxu_excl_cv, sx->sxu_lock);
+		sx->sxu_excl_wcnt--;
 		
 		if (error)
 			goto fail;
 	}
 
-	MPASS(sx->sx_cnt == 0);
+	MPASS(sx->sxu_cnt == 0);
 
 	/* Acquire an exclusive lock. */
-	sx->sx_cnt--;
-	sx->sx_xholder = curthread;
+	sx->sxu_cnt--;
+	sx->sxu_xholder = curthread;
 
-	lock_profile_obtain_lock_success(&sx->sx_object, waittime, file, line);
-	LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line);
-	WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line);
+	lock_profile_obtain_lock_success(&sx->sxu_object, waittime, file, line);
+	LOCK_LOG_LOCK("XLOCK", &sx->sxu_object, 0, 0, file, line);
+	WITNESS_LOCK(&sx->sxu_object, LOP_EXCLUSIVE, file, line);
 
  fail:
-	mtx_unlock(sx->sx_lock);
+	mtx_unlock(sx->sxu_lock);
 	return (error);
 }
 
 int
-_sx_try_xlock(struct sx *sx, const char *file, int line)
+_sxu_try_xlock(struct sxu *sx, const char *file, int line)
 {
 
-	mtx_lock(sx->sx_lock);
-	if (sx->sx_cnt == 0) {
-		sx->sx_cnt--;
-		sx->sx_xholder = curthread;
-		LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 1, file, line);
-		WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE | LOP_TRYLOCK, file,
+	mtx_lock(sx->sxu_lock);
+	if (sx->sxu_cnt == 0) {
+		sx->sxu_cnt--;
+		sx->sxu_xholder = curthread;
+		LOCK_LOG_TRY("XLOCK", &sx->sxu_object, 0, 1, file, line);
+		WITNESS_LOCK(&sx->sxu_object, LOP_EXCLUSIVE | LOP_TRYLOCK, file,
 		    line);
-		mtx_unlock(sx->sx_lock);
+		mtx_unlock(sx->sxu_lock);
 		return (1);
 	} else {
-		LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 0, file, line);
-		mtx_unlock(sx->sx_lock);
+		LOCK_LOG_TRY("XLOCK", &sx->sxu_object, 0, 0, file, line);
+		mtx_unlock(sx->sxu_lock);
 		return (0);
 	}
 }
 
 void
-_sx_sunlock(struct sx *sx, const char *file, int line)
+_sxu_sunlock(struct sxu *sx, const char *file, int line)
 {
 
-	_sx_assert(sx, SX_SLOCKED, file, line);
-	mtx_lock(sx->sx_lock);
+	_sxu_assert(sx, SXU_SLOCKED, file, line);
+	mtx_lock(sx->sxu_lock);
 
-	WITNESS_UNLOCK(&sx->sx_object, 0, file, line);
+	WITNESS_UNLOCK(&sx->sxu_object, 0, file, line);
 
 	/* Release. */
-	sx->sx_cnt--;
+	sx->sxu_cnt--;
 
 	/*
 	 * If we just released the last shared lock, wake any waiters up, giving
@@ -270,143 +270,143 @@
 	 * lockers won't be blocked forever, don't wake shared lock waiters if
 	 * there are exclusive lock waiters.
 	 */
-	if (sx->sx_cnt == 0)
-		lock_profile_release_lock(&sx->sx_object);
+	if (sx->sxu_cnt == 0)
+		lock_profile_release_lock(&sx->sxu_object);
 
-	if (sx->sx_excl_wcnt > 0) {
-		if (sx->sx_cnt == 0)
-			cv_signal(&sx->sx_excl_cv);
-	} else if (sx->sx_shrd_wcnt > 0) /* XXX why would shrd_wcnt be > 0 if the holder is shared? */
-		cv_broadcast(&sx->sx_shrd_cv);
+	if (sx->sxu_excl_wcnt > 0) {
+		if (sx->sxu_cnt == 0)
+			cv_signal(&sx->sxu_excl_cv);
+	} else if (sx->sxu_shrd_wcnt > 0) /* XXX why would shrd_wcnt be > 0 if the holder is shared? */
+		cv_broadcast(&sx->sxu_shrd_cv);
 
-	LOCK_LOG_LOCK("SUNLOCK", &sx->sx_object, 0, 0, file, line);
+	LOCK_LOG_LOCK("SUNLOCK", &sx->sxu_object, 0, 0, file, line);
 
-	mtx_unlock(sx->sx_lock);
+	mtx_unlock(sx->sxu_lock);
 }
 
 void
-_sx_xunlock(struct sx *sx, const char *file, int line)
+_sxu_xunlock(struct sxu *sx, const char *file, int line)
 {
 
-	_sx_assert(sx, SX_XLOCKED, file, line);
-	mtx_lock(sx->sx_lock);
-	MPASS(sx->sx_cnt == -1);
+	_sxu_assert(sx, SXU_XLOCKED, file, line);
+	mtx_lock(sx->sxu_lock);
+	MPASS(sx->sxu_cnt == -1);
 
-	WITNESS_UNLOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line);
+	WITNESS_UNLOCK(&sx->sxu_object, LOP_EXCLUSIVE, file, line);
 
 	/* Release. */
-	sx->sx_cnt++;
-	sx->sx_xholder = NULL;
+	sx->sxu_cnt++;
+	sx->sxu_xholder = NULL;
 
-	lock_profile_release_lock(&sx->sx_object);
+	lock_profile_release_lock(&sx->sxu_object);
 	/*
 	 * Wake up waiters if there are any.  Give precedence to slock waiters.
 	 */
-	if (sx->sx_shrd_wcnt > 0)
-		cv_broadcast(&sx->sx_shrd_cv);
-	else if (sx->sx_excl_wcnt > 0)
-		cv_signal(&sx->sx_excl_cv);
+	if (sx->sxu_shrd_wcnt > 0)
+		cv_broadcast(&sx->sxu_shrd_cv);
+	else if (sx->sxu_excl_wcnt > 0)
+		cv_signal(&sx->sxu_excl_cv);
 
-	LOCK_LOG_LOCK("XUNLOCK", &sx->sx_object, 0, 0, file, line);
+	LOCK_LOG_LOCK("XUNLOCK", &sx->sxu_object, 0, 0, file, line);
 
-	mtx_unlock(sx->sx_lock);
+	mtx_unlock(sx->sxu_lock);
 }
 
 int
-_sx_try_upgrade(struct sx *sx, const char *file, int line)
+_sxu_try_upgrade(struct sxu *sx, const char *file, int line)
 {
 
-	_sx_assert(sx, SX_SLOCKED, file, line);
-	mtx_lock(sx->sx_lock);
+	_sxu_assert(sx, SXU_SLOCKED, file, line);
+	mtx_lock(sx->sxu_lock);
 
-	if (sx->sx_cnt == 1) {
-		sx->sx_cnt = -1;
-		sx->sx_xholder = curthread;
+	if (sx->sxu_cnt == 1) {
+		sx->sxu_cnt = -1;
+		sx->sxu_xholder = curthread;
 
-		LOCK_LOG_TRY("XUPGRADE", &sx->sx_object, 0, 1, file, line);
-		WITNESS_UPGRADE(&sx->sx_object, LOP_EXCLUSIVE | LOP_TRYLOCK,
+		LOCK_LOG_TRY("XUPGRADE", &sx->sxu_object, 0, 1, file, line);
+		WITNESS_UPGRADE(&sx->sxu_object, LOP_EXCLUSIVE | LOP_TRYLOCK,
 		    file, line);
 
-		mtx_unlock(sx->sx_lock);
+		mtx_unlock(sx->sxu_lock);
 		return (1);
 	} else {
-		LOCK_LOG_TRY("XUPGRADE", &sx->sx_object, 0, 0, file, line);
-		mtx_unlock(sx->sx_lock);
+		LOCK_LOG_TRY("XUPGRADE", &sx->sxu_object, 0, 0, file, line);
+		mtx_unlock(sx->sxu_lock);
 		return (0);
 	}
 }
 
 void
-_sx_downgrade(struct sx *sx, const char *file, int line)
+_sxu_downgrade(struct sxu *sx, const char *file, int line)
 {
 
-	_sx_assert(sx, SX_XLOCKED, file, line);
-	mtx_lock(sx->sx_lock);
-	MPASS(sx->sx_cnt == -1);
+	_sxu_assert(sx, SXU_XLOCKED, file, line);
+	mtx_lock(sx->sxu_lock);
+	MPASS(sx->sxu_cnt == -1);
 
-	WITNESS_DOWNGRADE(&sx->sx_object, 0, file, line);
+	WITNESS_DOWNGRADE(&sx->sxu_object, 0, file, line);
 
-	sx->sx_cnt = 1;
-	sx->sx_xholder = NULL;
-        if (sx->sx_shrd_wcnt > 0)
-                cv_broadcast(&sx->sx_shrd_cv);
+	sx->sxu_cnt = 1;
+	sx->sxu_xholder = NULL;
+        if (sx->sxu_shrd_wcnt > 0)
+                cv_broadcast(&sx->sxu_shrd_cv);
 
-	LOCK_LOG_LOCK("XDOWNGRADE", &sx->sx_object, 0, 0, file, line);
+	LOCK_LOG_LOCK("XDOWNGRADE", &sx->sxu_object, 0, 0, file, line);
 
-	mtx_unlock(sx->sx_lock);
+	mtx_unlock(sx->sxu_lock);
 }
 
 #ifdef INVARIANT_SUPPORT
 #ifndef INVARIANTS
-#undef	_sx_assert
+#undef	_sxu_assert
 #endif
 
 /*
- * In the non-WITNESS case, sx_assert() can only detect that at least
+ * In the non-WITNESS case, sxu_assert() can only detect that at least
  * *some* thread owns an slock, but it cannot guarantee that *this*
  * thread owns an slock.
  */
 void
-_sx_assert(struct sx *sx, int what, const char *file, int line)
+_sxu_assert(struct sxu *sx, int what, const char *file, int line)
 {
 
 	if (panicstr != NULL)
 		return;
 	switch (what) {
-	case SX_LOCKED:
-	case SX_SLOCKED:
+	case SXU_LOCKED:
+	case SXU_SLOCKED:
 #ifdef WITNESS
-		witness_assert(&sx->sx_object, what, file, line);
+		witness_assert(&sx->sxu_object, what, file, line);
 #else
-		mtx_lock(sx->sx_lock);
-		if (sx->sx_cnt <= 0 &&
-		    (what == SX_SLOCKED || sx->sx_xholder != curthread))
+		mtx_lock(sx->sxu_lock);
+		if (sx->sxu_cnt <= 0 &&
+		    (what == SXU_SLOCKED || sx->sxu_xholder != curthread))
 			panic("Lock %s not %slocked @ %s:%d\n",
-			    sx->sx_object.lo_name, (what == SX_SLOCKED) ?
+			    sx->sxu_object.lo_name, (what == SXU_SLOCKED) ?
 			    "share " : "", file, line);
-		mtx_unlock(sx->sx_lock);
+		mtx_unlock(sx->sxu_lock);
 #endif
 		break;
-	case SX_XLOCKED:
-		mtx_lock(sx->sx_lock);
-		if (sx->sx_xholder != curthread)
+	case SXU_XLOCKED:
+		mtx_lock(sx->sxu_lock);
+		if (sx->sxu_xholder != curthread)
 			panic("Lock %s not exclusively locked @ %s:%d\n",
-			    sx->sx_object.lo_name, file, line);
-		mtx_unlock(sx->sx_lock);
+			    sx->sxu_object.lo_name, file, line);
+		mtx_unlock(sx->sxu_lock);
 		break;
-	case SX_UNLOCKED:
+	case SXU_UNLOCKED:
 #ifdef WITNESS
-		witness_assert(&sx->sx_object, what, file, line);
+		witness_assert(&sx->sxu_object, what, file, line);
 #else
 		/*
 		 * We are able to check only exclusive lock here,
 		 * we cannot assert that *this* thread owns slock.
 		 */
-		mtx_lock(sx->sx_lock);
-		if (sx->sx_xholder == curthread)
+		mtx_lock(sx->sxu_lock);
+		if (sx->sxu_xholder == curthread)
 			panic("Lock %s exclusively locked @ %s:%d\n",
-			    sx->sx_object.lo_name, file, line);
-		mtx_unlock(sx->sx_lock);
+			    sx->sxu_object.lo_name, file, line);
+		mtx_unlock(sx->sxu_lock);
 #endif
 		break;
 	default:
@@ -418,23 +418,23 @@
 
 #ifdef DDB
 void
-db_show_sx(struct lock_object *lock)
+db_show_sxu(struct lock_object *lock)
 {
 	struct thread *td;
-	struct sx *sx;
+	struct sxu *sx;
 
-	sx = (struct sx *)lock;
+	sx = (struct sxu *)lock;
 
 	db_printf(" state: ");
-	if (sx->sx_cnt < 0) {
-		td = sx->sx_xholder;
+	if (sx->sxu_cnt < 0) {
+		td = sx->sxu_xholder;
 		db_printf("XLOCK: %p (tid %d, pid %d, \"%s\")\n", td,
 		    td->td_tid, td->td_proc->p_pid, td->td_proc->p_comm);
-	} else if (sx->sx_cnt > 0)
-		db_printf("SLOCK: %d locks\n", sx->sx_cnt);
+	} else if (sx->sxu_cnt > 0)
+		db_printf("SLOCK: %d locks\n", sx->sxu_cnt);
 	else
 		db_printf("UNLOCKED\n");
-	db_printf(" waiters: %d shared, %d exclusive\n", sx->sx_shrd_wcnt,
-	    sx->sx_excl_wcnt);
+	db_printf(" waiters: %d shared, %d exclusive\n", sx->sxu_shrd_wcnt,
+	    sx->sxu_excl_wcnt);
 }
 #endif

==== //depot/projects/kmacy_sun4v/src/sys/sys/sxu.h#2 (text+ko) ====

@@ -34,35 +34,36 @@
 #include <sys/_lock.h>
 #include <sys/condvar.h>	/* XXX */
 
-struct sx {
-	struct lock_object sx_object;	/* Common lock properties. */
-	struct mtx	*sx_lock;	/* General protection lock. */
-	int		sx_cnt;		/* -1: xlock, > 0: slock count. */
-	struct cv	sx_shrd_cv;	/* slock waiters. */
-	int		sx_shrd_wcnt;	/* Number of slock waiters. */
-	struct cv	sx_excl_cv;	/* xlock waiters. */
-	int		sx_excl_wcnt;	/* Number of xlock waiters. */
-	struct thread	*sx_xholder;	/* Thread presently holding xlock. */
+struct sxu {
+	struct lock_object sxu_object;	/* Common lock properties. */
+	struct mtx	*sxu_lock;	/* General protection lock. */
+	int		sxu_cnt;	/* -1: xlock, > 0: slock count. */
+	struct cv	sxu_shrd_cv;	/* slock waiters. */
+	int		sxu_shrd_wcnt;	/* Number of slock waiters. */
+	struct cv	sxu_excl_cv;	/* xlock waiters. */
+	int		sxu_excl_wcnt;	/* Number of xlock waiters. */
+	struct thread	*sxu_xholder;	/* Thread presently holding xlock. */
+	struct cv	sxu_drain_cv;	/* drain waiter. */
 };
 
 #ifdef _KERNEL
-void	sx_sysinit(void *arg);
-void	sx_init(struct sx *sx, const char *description);
-void	sx_destroy(struct sx *sx);
-void	_sx_slock(struct sx *sx, const char *file, int line);
-void	_sx_xlock(struct sx *sx, const char *file, int line);
-int	_sx_try_slock(struct sx *sx, const char *file, int line);
-int	_sx_try_xlock(struct sx *sx, const char *file, int line);
-void	_sx_sunlock(struct sx *sx, const char *file, int line);
-void	_sx_xunlock(struct sx *sx, const char *file, int line);
-int	_sx_try_upgrade(struct sx *sx, const char *file, int line);
-void	_sx_downgrade(struct sx *sx, const char *file, int line);
+void	sxu_sysinit(void *arg);
+void	sxu_init(struct sxu *sx, const char *description);
+void	sxu_destroy(struct sxu *sx);
+void	_sxu_slock(struct sxu *sx, int timo, const char *file, int line);
+void	_sxu_xlock(struct sxu *sx, int timo, const char *file, int line);
+int	_sxu_try_slock(struct sxu *sx, const char *file, int line);
+int	_sxu_try_xlock(struct sxu *sx, const char *file, int line);
+void	_sxu_sunlock(struct sxu *sx, const char *file, int line);
+void	_sxu_xunlock(struct sxu *sx, const char *file, int line);
+int	_sxu_try_upgrade(struct sxu *sx, const char *file, int line);
+void	_sxu_downgrade(struct sxu *sx, const char *file, int line);
 #ifdef INVARIANT_SUPPORT
-void	_sx_assert(struct sx *sx, int what, const char *file, int line);
+void	_sxu_assert(struct sxu *sxu, int what, const char *file, int line);
 #endif
 
 struct sx_args {
-	struct sx 	*sa_sx;
+	struct sxu 	*sa_sxu;
 	const char	*sa_desc;
 };
 
@@ -71,24 +72,26 @@
 		(sxa),							\
 		(desc)							\
 	};								\
-	SYSINIT(name##_sx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE,	\
-	    sx_sysinit, &name##_args);					\
-	SYSUNINIT(name##_sx_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE,	\
-	    sx_destroy, (sxa))
+	SYSINIT(name##_sxu_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE,	\
+	    sxu_sysinit, &name##_args);					\
+	SYSUNINIT(name##_sxu_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE,	\
+	    sxu_destroy, (sxa))
 
-#define	sx_slock(sx)		_sx_slock((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_xlock(sx)		_sx_xlock((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_try_slock(sx)	_sx_try_slock((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_try_xlock(sx)	_sx_try_xlock((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_sunlock(sx)		_sx_sunlock((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_xunlock(sx)		_sx_xunlock((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_try_upgrade(sx)	_sx_try_upgrade((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_downgrade(sx)	_sx_downgrade((sx), LOCK_FILE, LOCK_LINE)
-#define	sx_unlock(sx) do {						\
+#define	sxu_slock(sx)		_sxu_slock((sx), (0), LOCK_FILE, LOCK_LINE)
+#define	sxu_xlock(sx)		_sxu_xlock((sx), (0),  LOCK_FILE, LOCK_LINE)
+#define	sxu_slock_timedwait(sx, timo)	_sxu_slock((sx), (timo), LOCK_FILE, LOCK_LINE)
+#define	sxu_xlock_timedwait(sx, timo)	_sxu_xlock((sx), (timo), LOCK_FILE, LOCK_LINE)
+#define	sxu_try_slock(sx)	_sxu_try_slock((sx), LOCK_FILE, LOCK_LINE)
+#define	sxu_try_xlock(sx)	_sxu_try_xlock((sx), LOCK_FILE, LOCK_LINE)
+#define	sxu_sunlock(sx)		_sxu_sunlock((sx), LOCK_FILE, LOCK_LINE)
+#define	sxu_xunlock(sx)		_sxu_xunlock((sx), LOCK_FILE, LOCK_LINE)
+#define	sxu_try_upgrade(sx)	_sxu_try_upgrade((sx), LOCK_FILE, LOCK_LINE)
+#define	sxu_downgrade(sx)	_sxu_downgrade((sx), LOCK_FILE, LOCK_LINE)
+#define	sxu_unlock(sx) do {						\
 	if ((sx)->sx_cnt < 0)						\
-		sx_xunlock(sx);						\
+		sxu_xunlock(sx);					\
 	else								\
-		sx_sunlock(sx);						\
+		sxu_sunlock(sx);					\
 } while (0)
 
 #if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
@@ -99,11 +102,11 @@
 #endif
 
 #ifdef INVARIANTS
-#define	sx_assert(sx, what)	_sx_assert((sx), (what), LOCK_FILE, LOCK_LINE)
+#define	sxu_assert(sx, what)	_sxu_assert((sx), (what), LOCK_FILE, LOCK_LINE)
 #else
-#define	sx_assert(sx, what)
+#define	sxu_assert(sx, what)
 #endif
 
 #endif /* _KERNEL */
 
-#endif /* !_SYS_SX_H_ */
+#endif /* !_SYS_SXU_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606280354.k5S3sdtZ039391>