Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix: fix compile error in freebsd.c

  • Loading branch information...
bnoordhuis committed Sep 27, 2011
1 parent 9db39bb commit ceff85dcfbaebe929954c3dd7d6e8330300d6b37
Showing with 14 additions and 3 deletions.
  1. +14 −3 src/unix/freebsd.c
@@ -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) {
@@ -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;
@@ -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_;
}

0 comments on commit ceff85d

Please sign in to comment.
You can’t perform that action at this time.