diff options
author | tommycli@chromium.org <tommycli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 14:23:56 +0000 |
---|---|---|
committer | tommycli@chromium.org <tommycli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 14:23:56 +0000 |
commit | 5c0b44355d76bc88064b1363fe1591668b536da5 (patch) | |
tree | 40ad7a3881c473a356dc8b7653b2420fb49f22e2 /base/sequence_checker_impl.cc | |
parent | 7a4fa4725a1b557b178c8053c5c7dd7ea8db9141 (diff) | |
download | chromium_src-5c0b44355d76bc88064b1363fe1591668b536da5.zip chromium_src-5c0b44355d76bc88064b1363fe1591668b536da5.tar.gz chromium_src-5c0b44355d76bc88064b1363fe1591668b536da5.tar.bz2 |
base: Re-apply WeakPtr support for SequencedWorkerPools, fixing deadlock
This reverts the revert found here: https://codereview.chromium.org/19882002
It also fixes the deadlock that caused the revert, reported here:
http://crbug.com/261448
Patchset 1 is simply what was originally committed (and reverted). Subsequent patchsets show the fix of the deadlock problem.
BUG=165590
TBR=darin
Review URL: https://chromiumcodereview.appspot.com/20163004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213906 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sequence_checker_impl.cc')
-rw-r--r-- | base/sequence_checker_impl.cc | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/base/sequence_checker_impl.cc b/base/sequence_checker_impl.cc index 24d9ed9..e95b8ee 100644 --- a/base/sequence_checker_impl.cc +++ b/base/sequence_checker_impl.cc @@ -4,28 +4,43 @@ #include "base/sequence_checker_impl.h" -#include "base/sequenced_task_runner.h" - namespace base { -SequenceCheckerImpl::SequenceCheckerImpl( - const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) - : sequenced_task_runner_(sequenced_task_runner) {} +SequenceCheckerImpl::SequenceCheckerImpl() + : sequence_token_assigned_(false) { + AutoLock auto_lock(lock_); + EnsureSequenceTokenAssigned(); +} SequenceCheckerImpl::~SequenceCheckerImpl() {} -bool SequenceCheckerImpl::CalledOnValidSequence() const { +bool SequenceCheckerImpl::CalledOnValidSequencedThread() const { AutoLock auto_lock(lock_); - return sequenced_task_runner_.get() ? - sequenced_task_runner_->RunsTasksOnCurrentThread() : - thread_checker_.CalledOnValidThread(); + EnsureSequenceTokenAssigned(); + + // If this thread is not associated with a SequencedWorkerPool, + // SequenceChecker behaves as a ThreadChecker. See header for details. + if (!sequence_token_.IsValid()) + return thread_checker_.CalledOnValidThread(); + + return sequence_token_.Equals( + SequencedWorkerPool::GetSequenceTokenForCurrentThread()); } -void SequenceCheckerImpl::ChangeSequence( - const scoped_refptr<SequencedTaskRunner>& sequenced_task_runner) { +void SequenceCheckerImpl::DetachFromSequence() { AutoLock auto_lock(lock_); - sequenced_task_runner_ = sequenced_task_runner; thread_checker_.DetachFromThread(); + sequence_token_assigned_ = false; + sequence_token_ = SequencedWorkerPool::SequenceToken(); +} + +void SequenceCheckerImpl::EnsureSequenceTokenAssigned() const { + lock_.AssertAcquired(); + if (sequence_token_assigned_) + return; + + sequence_token_assigned_ = true; + sequence_token_ = SequencedWorkerPool::GetSequenceTokenForCurrentThread(); } } // namespace base |