0

我有古蒂尔的 sysinfo.cc 文件,与这个文件相同: https ://github.com/cloudera/kudu/blob/master/src/kudu/gutil/sysinfo.cc#L248 我想知道 InitializeSystemInfo()鉴于我对 C++ 不太熟悉,该函数适用于 Linux。

我在第 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';
4

1 回答 1

0

右大括号在第 305 行。

该文件中的编程风格很难阅读,因为该函数有几个屏幕长并使用多个#ifdef分支。不过这是必要的。该源文件对其余代码隐藏了特定于操作系统的部分,因此它可能看起来很复杂。

其他代码可以只访问cpuinfo_cycles_per_second变量,这使得 API 非常简单。

于 2019-02-06T01:12:10.537 回答