Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Jun 2010 13:04:49 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        src-committers@freebsd.org
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org
Subject:   Re: svn commit: r209050 - head/sys/sys
Message-ID:  <201006111304.49966.jhb@freebsd.org>
In-Reply-To: <201006111556.o5BFuIEi020826@svn.freebsd.org>
References:  <201006111556.o5BFuIEi020826@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 11 June 2010 11:56:18 am John Baldwin wrote:
> Author: jhb
> Date: Fri Jun 11 15:56:18 2010
> New Revision: 209050
> URL: http://svn.freebsd.org/changeset/base/209050
> 
> Log:
>   Add helper macros to iterate over available CPUs in the system.
>   CPU_FOREACH(i) iterates over the CPU IDs of all available CPUs.  The
>   CPU_FIRST() and CPU_NEXT(i) macros can also be used to iterate over
>   available CPU IDs.  CPU_NEXT(i) wraps around to CPU_FIRST() rather than
>   returning some sort of terminator.

The intended use case for CPU_FIRST() and CPU_NEXT() is to use it to do things 
like this:

	u_int hash[64];
	int i, j;

	j = CPU_FIRST();
	for (i = 0; i < 64; i++) {
		hash[i] = j;
		j = CPU_NEXT(j);
	}

If the auto-wrapping semantics of CPU_NEXT() is too odd, we could make it 
return NOCPU when it hits the end of the list instead perhaps and use some 
other macro to provide the current CPU_NEXT()-like behavior.

-- 
John Baldwin



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