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

Unified Diff: tools/battor_agent/battor_agent_bin.cc

Issue 2062393002: [battor agent] Make BattOr agent block until the BattOrAgent is created (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment about why sync is necessary Created 4 years, 6 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: tools/battor_agent/battor_agent_bin.cc
diff --git a/tools/battor_agent/battor_agent_bin.cc b/tools/battor_agent/battor_agent_bin.cc
index 5cfce66a7b6492e795a36cacf8431941e366c80a..6a70127bc47381338b85e2f3fd53cdbf3aa86186 100644
--- a/tools/battor_agent/battor_agent_bin.cc
+++ b/tools/battor_agent/battor_agent_bin.cc
@@ -141,10 +141,18 @@ class BattOrAgentBin : public BattOrAgent::Listener {
ExitFromThreadStartFailure(kIoThreadName);
}
+ // Block until the creation of the BattOrAgent is complete. This doesn't
+ // seem necessary because we're posting the creation to the IO thread
+ // before posting any commands, so we're guaranteed that the creation
+ // will happen first. However, the crashes that happen without this sync
+ // mechanism in place say otherwise.
+ base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED);
io_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&BattOrAgentBin::CreateAgent, base::Unretained(this), path,
- base::ThreadTaskRunnerHandle::Get()));
+ base::ThreadTaskRunnerHandle::Get(), &done));
+ done.Wait();
}
// Performs any cleanup necessary after the BattOr binary is done running.
@@ -272,7 +280,8 @@ class BattOrAgentBin : public BattOrAgent::Listener {
// and deleting it, MUST happen on the IO thread.
void CreateAgent(
const std::string& path,
- scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) {
+ scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner,
+ base::WaitableEvent* done) {
// In Chrome, we already have a file thread running. Because the Chrome
// serial library relies on having it available, we have to spin up our own.
if (!file_thread_.Start())
@@ -280,6 +289,7 @@ class BattOrAgentBin : public BattOrAgent::Listener {
agent_.reset(new BattOrAgent(path, this, file_thread_.task_runner(),
ui_thread_task_runner));
+ done->Signal();
}
// Postable task for deleting the BattOrAgent. See the comment for
« 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