Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: fix compile error in freebsd.c
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Sep 27, 2011
1 parent 9db39bb commit ceff85d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/unix/freebsd.c
Expand Up @@ -197,10 +197,12 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
cur = 0;
uv_cpu_info_t* cpu_info;
char model[512];
long* cp_times;
int numcpus;
size_t size;
uv_cpu_info_t* cpu_info;
int i;

size = sizeof(model);
if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
Expand Down Expand Up @@ -229,14 +231,22 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}

size = maxcpus * CPUSTATES * sizeof(long);
long cp_times[size];

cp_times = malloc(size);
if (cp_times == NULL) {
free(*cpu_infos);
return uv__new_sys_error(ENOMEM);
}

if (sysctlbyname("kern.cp_times", &cp_times, &size, NULL, 0) < 0) {
free(cp_times);
free(*cpu_infos);
return uv__new_sys_error(errno);
}

for (int i = 0; i < numcpus; i++) {
for (i = 0; i < numcpus; i++) {
cpu_info = &(*cpu_infos)[i];

cpu_info->cpu_times.user = (uint64_t)(cp_times[CP_USER+cur]) * multiplier;
Expand All @@ -251,6 +261,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cur+=CPUSTATES;
}

free(cp_times);
return uv_ok_;
}

Expand Down

0 comments on commit ceff85d

Please sign in to comment.