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"
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_
)
42 sequence_token_assigned_
= true;
43 sequence_token_
= SequencedWorkerPool::GetSequenceTokenForCurrentThread();