Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2408)

Unified Diff: chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc

Issue 426303002: Fix race condition in CpuInfoProvider::QueryCpuTimePerProcessor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
diff --git a/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc b/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
index 242226289a7fe0b34dae61e3abd50612dd978f26..5674390dea0cd8d0d5360d7f2a9f58af00af7b75 100644
--- a/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
+++ b/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
@@ -37,12 +37,18 @@ bool CpuInfoProvider::QueryCpuTimePerProcessor(
if (line.compare(0, 3, "cpu") != 0)
continue;
+ // Cope with kernel race condition when /proc/stat does not reflect to the
Pawel Osciak 2014/08/04 00:55:21 s/to//
Justin Chuang 2014/08/04 08:12:03 Acknowledged.
+ // current number of online processors in time. Also handle a less-likely
Pawel Osciak 2014/08/04 00:55:21 s/in time//
Justin Chuang 2014/08/04 08:12:03 Acknowledged.
+ // race condition when the number of online processors is changed after it
+ // has been decided in CpuInfoProvider::QueryInfo().
+ if (i == infos->size())
Pawel Osciak 2014/08/04 00:55:22 Please explain how this actually handles the issue
Justin Chuang 2014/08/04 08:12:04 Thanks for the comments. It's actually a race cond
+ return false;
+
uint64 user = 0, nice = 0, sys = 0, idle = 0;
int vals = sscanf(line.c_str(), "%*s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64,
&user, &nice, &sys, &idle);
DCHECK_EQ(4, vals);
- DCHECK(i < infos->size());
infos->at(i)->usage.kernel = static_cast<double>(sys);
infos->at(i)->usage.user = static_cast<double>(user + nice);
infos->at(i)->usage.idle = static_cast<double>(idle);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698