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

Unified Diff: base/task_scheduler/scheduler_worker.cc

Issue 2430633003: TaskScheduler: Record TaskScheduler.NumTasksBeforeDetach.* from OnDetach(). (Closed)
Patch Set: CR gab #3 rebase Created 4 years, 2 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 | « base/task_scheduler/scheduler_worker.h ('k') | base/task_scheduler/scheduler_worker_pool_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/scheduler_worker.cc
diff --git a/base/task_scheduler/scheduler_worker.cc b/base/task_scheduler/scheduler_worker.cc
index e64ca61de00600db5cc08b2d7b7937f742db860f..054227193bbad5a82c3bbe6830736b80d9919dbb 100644
--- a/base/task_scheduler/scheduler_worker.cc
+++ b/base/task_scheduler/scheduler_worker.cc
@@ -36,10 +36,7 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
// Set if this thread was detached.
std::unique_ptr<Thread> detached_thread;
- outer_->delegate_->OnMainEntry(
- outer_, outer_->last_detach_time_.is_null()
- ? TimeDelta::Max()
- : TimeTicks::Now() - outer_->last_detach_time_);
+ outer_->delegate_->OnMainEntry(outer_);
// A SchedulerWorker starts out waiting for work.
WaitForWork();
@@ -60,9 +57,9 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
if (outer_->delegate_->CanDetach(outer_)) {
detached_thread = outer_->Detach();
if (detached_thread) {
+ outer_ = nullptr;
DCHECK_EQ(detached_thread.get(), this);
PlatformThread::Detach(thread_handle_);
- outer_ = nullptr;
break;
}
}
@@ -256,7 +253,11 @@ std::unique_ptr<SchedulerWorker::Thread> SchedulerWorker::Detach() {
// guarantee that we call GetWork() after a successful wakeup.
if (thread_->IsWakeUpPending())
return nullptr;
- last_detach_time_ = TimeTicks::Now();
+
+ // Call OnDetach() within the scope of |thread_lock_| to prevent the delegate
+ // from being used concurrently from an old and a new thread.
+ delegate_->OnDetach();
+
return std::move(thread_);
}
« no previous file with comments | « base/task_scheduler/scheduler_worker.h ('k') | base/task_scheduler/scheduler_worker_pool_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698