get rid of magic numbers - get bound from parameter passed

This commit is contained in:
marschap
2007-04-07 14:46:04 +00:00
parent 444eb2b18c
commit d682e0955a
4 changed files with 32 additions and 20 deletions
+8 -5
View File
@@ -394,8 +394,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
load_type curr_load;
size = sizeof(int);
if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0)
{
if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) {
perror("sysctl hw.ncpu");
return(FALSE);
}
@@ -403,11 +402,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
if (machine_get_load(&curr_load) == FALSE)
return(FALSE);
if (numcpus == NULL)
return(FALSE);
/* restrict #CPUs to max. *numcpus */
num = (*numcpus >= num) ? num : *numcpus;
*numcpus = num;
num = num > 8 ? 8 : num;
/* Don't know how to get per-cpu-load values */
for (i = 0; i < num; i++)
{
for (i = 0; i < num; i++) {
result[i] = curr_load;
}
+8 -5
View File
@@ -343,8 +343,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
load_type curr_load;
size = sizeof(int);
if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0)
{
if (sysctlbyname("hw.ncpu", &num, &size, NULL, 0) < 0) {
perror("sysctl hw.ncpu");
return(FALSE);
}
@@ -352,11 +351,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
if (machine_get_load(&curr_load) == FALSE)
return(FALSE);
if (numcpus == NULL)
return(FALSE);
/* restrict #CPUs to max. *numcpus */
num = (*numcpus >= num) ? num : *numcpus;
*numcpus = num;
num = num > 8 ? 8 : num;
/* Don't know how to get per-cpu-load values */
for (i = 0; i < num; i++)
{
for (i = 0; i < num; i++) {
result[i] = curr_load;
}
+8 -5
View File
@@ -325,8 +325,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
mib[1] = HW_NCPU;
size = sizeof(int);
if (sysctl(mib, 2, &num, &size, NULL, 0) < 0)
{
if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) {
perror("sysctl hw.ncpu");
return(FALSE);
}
@@ -334,11 +333,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
if (machine_get_load(&curr_load) == FALSE)
return(FALSE);
if (numcpus == NULL)
return(FALSE);
/* restrict #CPUs to max. *numcpus */
num = (*numcpus >= num) ? num : *numcpus;
*numcpus = num;
num = num > 8 ? 8 : num;
/* Don't know how to get per-cpu-load values */
for (i = 0; i < num; i++)
{
for (i = 0; i < num; i++) {
result[i] = curr_load;
}
+8 -5
View File
@@ -330,8 +330,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
mib[1] = HW_NCPU;
size = sizeof(int);
if (sysctl(mib, 2, &num, &size, NULL, 0) < 0)
{
if (sysctl(mib, 2, &num, &size, NULL, 0) < 0) {
perror("sysctl hw.ncpu");
return(FALSE);
}
@@ -339,11 +338,15 @@ int machine_get_smpload(load_type *result, int *numcpus)
if (machine_get_load(&curr_load) == FALSE)
return(FALSE);
if (numcpus == NULL)
return(FALSE);
/* restrict #CPUs to max. *numcpus */
num = (*numcpus >= num) ? num : *numcpus;
*numcpus = num;
num = num > 8 ? 8 : num;
/* Don't know how to get per-cpu-load values */
for (i = 0; i < num; i++)
{
for (i = 0; i < num; i++) {
result[i] = curr_load;
}