1
0
mirror of https://github.com/golang/go synced 2024-10-05 16:41:21 -06:00

[dev.power64] runtime: replace getproccount with simpler code

This runs once. There is no need for inscrutable algorithms.
Also it doesn't compile correctly with 9c.

LGTM=minux
R=minux
CC=golang-codereviews
https://golang.org/cl/130000043
This commit is contained in:
Russ Cox 2014-08-14 14:34:25 -04:00
parent 25bde37af4
commit ecbe6b9f7f

View File

@ -78,19 +78,22 @@ static int32
getproccount(void)
{
uintptr buf[16], t;
int32 r, cnt, i;
int32 r, n, i;
cnt = 0;
r = runtime·sched_getaffinity(0, sizeof(buf), buf);
if(r > 0)
if(r <= 0)
return 1;
n = 0;
for(i = 0; i < r/sizeof(buf[0]); i++) {
t = buf[i];
t = t - ((t >> 1) & 0x5555555555555555ULL);
t = (t & 0x3333333333333333ULL) + ((t >> 2) & 0x3333333333333333ULL);
cnt += (int32)((((t + (t >> 4)) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);
while(t != 0) {
n += t&1;
t >>= 1;
}
}
return cnt ? cnt : 1;
if(n < 1)
n = 1;
return n;
}
// Clone, the Linux rfork.