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

Unified Diff: base/threading/thread_checker_impl.cc

Issue 2213263002: Make ThreadChecker::CalledOnValidThread() return true when called from the same task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab #6 (fix comment) Created 4 years, 4 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
Index: base/threading/thread_checker_impl.cc
diff --git a/base/threading/thread_checker_impl.cc b/base/threading/thread_checker_impl.cc
index 11c2b95b6fcfed31ecab6d442c08226fb5187b04..d5ccbdb943db85d5a399c47f5606075e7f1109e2 100644
--- a/base/threading/thread_checker_impl.cc
+++ b/base/threading/thread_checker_impl.cc
@@ -19,6 +19,11 @@ bool ThreadCheckerImpl::CalledOnValidThread() const {
AutoLock auto_lock(lock_);
EnsureAssigned();
+ // Always return true when called from the task from which this
+ // ThreadCheckerImpl was assigned to a thread.
+ if (task_token_ == TaskToken::GetForCurrentThread())
+ return true;
+
// If this ThreadCheckerImpl is bound to a valid SequenceToken, it must be
// equal to the current SequenceToken and there must be a registered
// ThreadTaskRunnerHandle. Otherwise, the fact that the current task runs on
@@ -35,6 +40,7 @@ bool ThreadCheckerImpl::CalledOnValidThread() const {
void ThreadCheckerImpl::DetachFromThread() {
AutoLock auto_lock(lock_);
thread_id_ = PlatformThreadRef();
+ task_token_ = TaskToken();
sequence_token_ = SequenceToken();
}
@@ -44,6 +50,7 @@ void ThreadCheckerImpl::EnsureAssigned() const {
return;
thread_id_ = PlatformThread::CurrentRef();
+ task_token_ = TaskToken::GetForCurrentThread();
sequence_token_ = SequenceToken::GetForCurrentThread();
}

Powered by Google App Engine
This is Rietveld 408576698