Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / base / sequence_checker_impl.cc
blobe95b8ee5f3e25e639a609e5cb0c5aad291fe6e59
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sequence_checker_impl.h"
7 namespace base {
9 SequenceCheckerImpl::SequenceCheckerImpl()
10 : sequence_token_assigned_(false) {
11 AutoLock auto_lock(lock_);
12 EnsureSequenceTokenAssigned();
15 SequenceCheckerImpl::~SequenceCheckerImpl() {}
17 bool SequenceCheckerImpl::CalledOnValidSequencedThread() const {
18 AutoLock auto_lock(lock_);
19 EnsureSequenceTokenAssigned();
21 // If this thread is not associated with a SequencedWorkerPool,
22 // SequenceChecker behaves as a ThreadChecker. See header for details.
23 if (!sequence_token_.IsValid())
24 return thread_checker_.CalledOnValidThread();
26 return sequence_token_.Equals(
27 SequencedWorkerPool::GetSequenceTokenForCurrentThread());
30 void SequenceCheckerImpl::DetachFromSequence() {
31 AutoLock auto_lock(lock_);
32 thread_checker_.DetachFromThread();
33 sequence_token_assigned_ = false;
34 sequence_token_ = SequencedWorkerPool::SequenceToken();
37 void SequenceCheckerImpl::EnsureSequenceTokenAssigned() const {
38 lock_.AssertAcquired();
39 if (sequence_token_assigned_)
40 return;
42 sequence_token_assigned_ = true;
43 sequence_token_ = SequencedWorkerPool::GetSequenceTokenForCurrentThread();
46 } // namespace base