On Sunday 13 June 2010 9:41:38 am Lawrence Stewart wrote:
> On 06/13/10 20:10, Pawel Jakub Dawidek wrote:
> > On Sun, Jun 13, 2010 at 02:39:55AM +0000, Lawrence Stewart wrote:
> >> Author: lstewart
> >> Date: Sun Jun 13 02:39:55 2010
> >> New Revision: 209119
> >> URL: http://svn.freebsd.org/changeset/base/209119
> >>
> >> Log:
> >>    Add a utility macro to simplify calculating an aggregate sum from a 
DPCPU
> >>    counter variable.
> >>
> >>    Sponsored by:   FreeBSD Foundation
> >>    Reviewed by:    jhb, rpaulo, rwatson (previous version of patch)
> >>    MFC after:      1 week
> >>
> >> Modified:
> >>    head/sys/sys/pcpu.h
> >>
> >> Modified: head/sys/sys/pcpu.h
> >> 
==============================================================================
> >> --- head/sys/sys/pcpu.h    Sun Jun 13 01:27:29 2010        (r209118)
> >> +++ head/sys/sys/pcpu.h    Sun Jun 13 02:39:55 2010        (r209119)
> >> @@ -106,6 +106,17 @@ extern uintptr_t dpcpu_off[];
> >>   #define  DPCPU_ID_GET(i, n)      (*DPCPU_ID_PTR(i, n))
> >>   #define  DPCPU_ID_SET(i, n, v)   (*DPCPU_ID_PTR(i, n) = v)
> >>
> >> +/*
> >> + * 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)
> >
> > I'd suggest first swapping variable declaration and '(sum) = 0;'.
> 
> Can do (will wait until consensus on other issues is reached first 
> before tweaking though).
> 
> > Also using 'i' as a counter in macro can easly lead to name collision.
> 
> I had a similar concern but after chatting with John on IRC felt it 
> wasn't such a big deal in this case.

Actually, I am a fan of using an inline function if possible to avoid the name 
collisions.

-- 
John Baldwin
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to