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

Unified Diff: base/debug/trace_event_impl.cc

Issue 491393002: Avoid deadlock during trace_event flush (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New simpler method Created 6 years, 3 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: base/debug/trace_event_impl.cc
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index cce900c2e61b6d8e1482d421069576b981a33b7e..db321e2bfa42c893e34acce70c37d802459c0e6f 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -1697,6 +1697,9 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
}
int generation = this->generation();
+ // Copy of thread_message_loops_ to be used without locking.
+ std::vector<scoped_refptr<SingleThreadTaskRunner> >
+ thread_message_loop_task_runners;
{
AutoLock lock(lock_);
DCHECK(!flush_message_loop_proxy_.get());
@@ -1713,16 +1716,22 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
for (hash_set<MessageLoop*>::const_iterator it =
thread_message_loops_.begin();
it != thread_message_loops_.end(); ++it) {
- (*it)->PostTask(
- FROM_HERE,
- Bind(&TraceLog::FlushCurrentThread, Unretained(this), generation));
+ thread_message_loop_task_runners.push_back((*it)->task_runner());
}
- flush_message_loop_proxy_->PostDelayedTask(
+ }
+ }
+
+ if (thread_message_loop_task_runners.size()) {
+ for (size_t i = 0; i < thread_message_loop_task_runners.size(); ++i) {
+ thread_message_loop_task_runners[i]->PostTask(
FROM_HERE,
- Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation),
- TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs));
- return;
+ Bind(&TraceLog::FlushCurrentThread, Unretained(this), generation));
}
+ flush_message_loop_proxy_->PostDelayedTask(
+ FROM_HERE,
+ Bind(&TraceLog::OnFlushTimeout, Unretained(this), generation),
+ TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs));
+ return;
}
FinishFlush(generation);
« 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