blob: e95b8ee5f3e25e639a609e5cb0c5aad291fe6e59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/sequence_checker_impl.h"
namespace base {
SequenceCheckerImpl::SequenceCheckerImpl()
: sequence_token_assigned_(false) {
AutoLock auto_lock(lock_);
EnsureSequenceTokenAssigned();
}
SequenceCheckerImpl::~SequenceCheckerImpl() {}
bool SequenceCheckerImpl::CalledOnValidSequencedThread() const {
AutoLock auto_lock(lock_);
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::DetachFromSequence() {
AutoLock auto_lock(lock_);
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
|