svn commit: r209050 - head/sys/sys
John Baldwin
jhb at freebsd.org
Fri Jun 11 17:05:05 UTC 2010
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
More information about the svn-src-head
mailing list