我有gutil的sysinfo.cc文件,与该文件相同: https://github.com/cloudera/kudu/blob/master/src/kudu/gutil/sysinfo.cc#L248 我想知道InitializeSystemInfo()函数是否可以在Linux上正常工作,因为我对C ++不太熟悉。
我在第248行上找不到此do语句的右括号,因此它仍然可以正确计算numcpus吗?
do { // we'll exit when the last read didn't read anything
// Move the next line to the beginning of the buffer
const int oldlinelen = strlen(line);
if (sizeof(line) == oldlinelen + 1) // oldlinelen took up entire line
line[0] = '\0';
else // still other lines left to save
memmove(line, line + oldlinelen+1, sizeof(line) - (oldlinelen+1));
// Terminate the new line, reading more if we can't find the newline
char* newline = strchr(line, '\n');
if (newline == NULL) {
const int linelen = strlen(line);
const int bytes_to_read = sizeof(line)-1 - linelen;
CHECK_GT(bytes_to_read, 0); // because the memmove recovered >=1 bytes
chars_read = read(fd, line + linelen, bytes_to_read);
line[linelen + chars_read] = '\0';
newline = strchr(line, '\n');
}
if (newline != NULL)
*newline = '\0';
答案 0 :(得分:0)
右括号在第305行。
此文件中的编程风格很难阅读,因为该函数有几个屏幕长,并且使用多个#ifdef
分支。虽然有必要。此源文件在其余代码中隐藏了特定于操作系统的部分,因此看起来可能很复杂。
其他代码只能访问cpuinfo_cycles_per_second
变量,这使API变得非常简单。