PERFORCE change 44608 for review

John Baldwin jhb at FreeBSD.org
Wed Dec 31 11:43:48 PST 2003


http://perforce.freebsd.org/chv.cgi?CH=44608

Change 44608 by jhb at jhb_blue on 2003/12/31 11:43:15

	Use a macro to simplify the trylock stuff and make it print out the
	recursion count each time as well.

Affected files ...

.. //depot/projects/smpng/sys/modules/crash/crash.c#7 edit

Differences ...

==== //depot/projects/smpng/sys/modules/crash/crash.c#7 (text+ko) ====

@@ -238,28 +238,22 @@
 			mtx_init(&test1_mtx, "test1", NULL, MTX_DEF);
 			mtx_init(&test1_mtx, "test2", NULL, MTX_DEF |
 			    MTX_RECURSE);
-			status = mtx_trylock(&test1_mtx);
-			printf("Try lock of unlocked test1: %d\n", status);
-			if (status)
-				mtx_unlock(&test1_mtx);
+#define TRYLOCK_TEST(lock, descr) do {					\
+	status = mtx_trylock((lock));					\
+	printf("Try lock of " descr ": %d;  recurse = %d\n",		\
+	    status, (lock)->mtx_recurse);				\
+	if (status)							\
+		mtx_unlock((lock));					\
+} while(0)
+			TRYLOCK_TEST(&test1_mtx, "unlocked test1");
 			mtx_lock(&test1_mtx);
-			status = mtx_trylock(&test1_mtx);
-			printf("Try lock of non-recursive locked test1: %d\n",
-			    status);
-			if (status)
-				mtx_unlock(&test1_mtx);
+			TRYLOCK_TEST(&test1_mtx, "non-recursive locked test1");
 			mtx_unlock(&test1_mtx);
-			status = mtx_trylock(&test2_mtx);
-			printf("Try lock of unlocked test2: %d\n", status);
-			if (status)
-				mtx_unlock(&test2_mtx);
+			TRYLOCK_TEST(&test2_mtx, "unlocked test2");
 			mtx_lock(&test2_mtx);
-			status = mtx_trylock(&test2_mtx);
-			printf("Try lock of recursive locked test2: %d\n",
-			    status);
-			if (status)
-				mtx_unlock(&test2_mtx);
+			TRYLOCK_TEST(&test2_mtx, "recursive locked test2");
 			mtx_unlock(&test2_mtx);
+#undef TRYLOCK_TEST
 			break;
 		default:
 			panic("event %d is bogus\n", event);


More information about the p4-projects mailing list