[Lldb-commits] [PATCH] D131081: [lldb] Prevent race condition when fetching /proc/cpuinfo

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 3 10:12:45 PDT 2022


labath added inline comments.


================
Comment at: lldb/source/Plugins/Process/Linux/Procfs.cpp:22
 Expected<ArrayRef<uint8_t>> lldb_private::process_linux::GetProcfsCpuInfo() {
   static Optional<std::vector<uint8_t>> cpu_info;
+  static Optional<std::string> error;
----------------
How about storing this as `ErrorOr<std::vector<uint8_t>>` (that's what `getProcFile` returns anyway), and initializing it via an immediately-evaluated lambda ?
I.e., something like
```
auto cpu_info = [] -> ErrorOr<std::vector<uint8_t>> {
  if (auto buffer_or_error = getProcFile("cpuinfo")) {
    return std::vector<uint8_t>(...);
  } else {
    return buffer_or_error.getError();
  }
}();
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131081/new/

https://reviews.llvm.org/D131081



More information about the lldb-commits mailing list