svn commit: r209325 - head/sys/sys

Lawrence Stewart lstewart at FreeBSD.org
Sat Jun 19 02:30:10 UTC 2010


Author: lstewart
Date: Sat Jun 19 02:30:10 2010
New Revision: 209325
URL: http://svn.freebsd.org/changeset/base/209325

Log:
  - Rename the internal for loop iterator to "_i" to avoid potential shadowing of
    external variables named "i". The "_" prefix is reserved for infrastructure
    type code and is therefore not expected to be used by normal code likely to
    call DPCPU_SUM(). [1]
  
  - Change DPCPU_SUM to return the sum rather than calculate and assign it
    internally. Usage is now: "sum = DPCPU_SUM(dpcpu_var, member_to_sum);" [2]
  
  - Fix some style nits. [3]
  
  Sponsored by:	FreeBSD Foundation
  Suggested by:	bde [3], mdf [1], kib [1,2], pjd [1,3]
  Reviewed by:	kib
  MFC after:	1 week (instead of r209119)

Modified:
  head/sys/sys/pcpu.h

Modified: head/sys/sys/pcpu.h
==============================================================================
--- head/sys/sys/pcpu.h	Sat Jun 19 00:41:29 2010	(r209324)
+++ head/sys/sys/pcpu.h	Sat Jun 19 02:30:10 2010	(r209325)
@@ -109,13 +109,17 @@ extern uintptr_t dpcpu_off[];
 /*
  * Utility macros.
  */
-#define DPCPU_SUM(n, var, sum)						\
-do {									\
-	(sum) = 0;							\
-	u_int i;							\
-	CPU_FOREACH(i)							\
-		(sum) += (DPCPU_ID_PTR(i, n))->var;			\
-} while (0)
+#define	DPCPU_SUM(n, var) __extension__					\
+({									\
+	u_int _i;							\
+	__typeof((DPCPU_PTR(n))->var) sum;				\
+									\
+	sum = 0;							\
+	CPU_FOREACH(_i) {						\
+		sum += (DPCPU_ID_PTR(_i, n))->var;			\
+	}								\
+	sum;								\
+})
 
 /* 
  * XXXUPS remove as soon as we have per cpu variable


More information about the svn-src-all mailing list