Skip to content

Commit

Permalink
deps: upgrade libuv to 7e59f9b
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Mar 2, 2013
1 parent 4b20f34 commit 7707acd
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions deps/uv/src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
# define CLOCK_BOOTTIME 7
#endif

static void read_models(unsigned int numcpus, uv_cpu_info_t* ci);
static int read_models(unsigned int numcpus, uv_cpu_info_t* ci);
static int read_times(unsigned int numcpus, uv_cpu_info_t* ci);
static void read_speeds(unsigned int numcpus, uv_cpu_info_t* ci);
static void read_times(unsigned int numcpus, uv_cpu_info_t* ci);
static unsigned long read_cpufreq(unsigned int cpunum);


Expand Down Expand Up @@ -420,10 +420,19 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
if (ci == NULL)
return uv__new_sys_error(ENOMEM);

read_models(numcpus, ci);
read_times(numcpus, ci);
if (read_models(numcpus, ci)) {
SAVE_ERRNO(free(ci));
return uv__new_sys_error(errno);
}

/* read_models() on x86 also reads the CPU speed from /proc/cpuinfo */
if (read_times(numcpus, ci)) {
SAVE_ERRNO(free(ci));
return uv__new_sys_error(errno);
}

/* read_models() on x86 also reads the CPU speed from /proc/cpuinfo.
* We don't check for errors here. Worst case, the field is left zero.
*/
if (ci[0].speed == 0)
read_speeds(numcpus, ci);

Expand All @@ -445,7 +454,7 @@ static void read_speeds(unsigned int numcpus, uv_cpu_info_t* ci) {
/* Also reads the CPU frequency on x86. The other architectures only have
* a BogoMIPS field, which may not be very accurate.
*/
static void read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
#if defined(__i386__) || defined(__x86_64__)
static const char model_marker[] = "model name\t: ";
static const char speed_marker[] = "cpu MHz\t\t: ";
Expand All @@ -470,7 +479,7 @@ static void read_models(unsigned int numcpus, uv_cpu_info_t* ci) {

fp = fopen("/proc/cpuinfo", "r");
if (fp == NULL)
return;
return -1;

model_idx = 0;
speed_idx = 0;
Expand Down Expand Up @@ -515,10 +524,12 @@ static void read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
ci[model_idx].model = strndup(inferred_model, strlen(inferred_model));
model_idx++;
}

return 0;
}


static void read_times(unsigned int numcpus, uv_cpu_info_t* ci) {
static int read_times(unsigned int numcpus, uv_cpu_info_t* ci) {
unsigned long clock_ticks;
struct uv_cpu_times_s ts;
unsigned long user;
Expand All @@ -538,7 +549,7 @@ static void read_times(unsigned int numcpus, uv_cpu_info_t* ci) {

fp = fopen("/proc/stat", "r");
if (fp == NULL)
return;
return -1;

if (!fgets(buf, sizeof(buf), fp))
abort();
Expand Down Expand Up @@ -583,6 +594,8 @@ static void read_times(unsigned int numcpus, uv_cpu_info_t* ci) {
ci[num++].cpu_times = ts;
}
fclose(fp);

return 0;
}


Expand Down

0 comments on commit 7707acd

Please sign in to comment.