OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sequence_checker_impl.h" | 5 #include "base/sequence_checker_impl.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 | |
7 namespace base { | 9 namespace base { |
8 | 10 |
9 SequenceCheckerImpl::SequenceCheckerImpl() | 11 SequenceCheckerImpl::SequenceCheckerImpl() { |
10 : sequence_token_assigned_(false) { | |
11 AutoLock auto_lock(lock_); | 12 AutoLock auto_lock(lock_); |
12 EnsureSequenceTokenAssigned(); | 13 EnsureSequenceTokenAssigned(); |
13 } | 14 } |
14 | 15 |
15 SequenceCheckerImpl::~SequenceCheckerImpl() {} | 16 SequenceCheckerImpl::~SequenceCheckerImpl() = default; |
16 | 17 |
17 bool SequenceCheckerImpl::CalledOnValidSequencedThread() const { | 18 bool SequenceCheckerImpl::CalledOnValidSequencedThread() const { |
18 AutoLock auto_lock(lock_); | 19 AutoLock auto_lock(lock_); |
19 EnsureSequenceTokenAssigned(); | 20 EnsureSequenceTokenAssigned(); |
20 | 21 |
21 // If this thread is not associated with a SequencedWorkerPool, | 22 if (sequence_token_.IsValid()) |
gab
2016/07/26 20:49:49
Do we even need IsValid() in a world where invalid
fdoray
2016/07/28 18:10:04
If we do that, we'll delegate to |thread_checker_|
| |
22 // SequenceChecker behaves as a ThreadChecker. See header for details. | 23 return sequence_token_ == SequenceToken::GetForCurrentThread(); |
23 if (!sequence_token_.IsValid()) | |
24 return thread_checker_.CalledOnValidThread(); | |
25 | 24 |
26 return sequence_token_.Equals( | 25 if (sequenced_worker_pool_token_.IsValid()) { |
27 SequencedWorkerPool::GetSequenceTokenForCurrentThread()); | 26 return sequenced_worker_pool_token_.Equals( |
27 SequencedWorkerPool::GetSequenceTokenForCurrentThread()); | |
28 } | |
29 | |
30 // SequenceChecker behaves as a ThreadChecker when it is not bound to a valid | |
31 // sequence token. | |
32 return thread_checker_.CalledOnValidThread(); | |
28 } | 33 } |
29 | 34 |
30 void SequenceCheckerImpl::DetachFromSequence() { | 35 void SequenceCheckerImpl::DetachFromSequence() { |
31 AutoLock auto_lock(lock_); | 36 AutoLock auto_lock(lock_); |
37 is_assigned_ = false; | |
38 sequence_token_ = SequenceToken(); | |
39 sequenced_worker_pool_token_ = SequencedWorkerPool::SequenceToken(); | |
32 thread_checker_.DetachFromThread(); | 40 thread_checker_.DetachFromThread(); |
33 sequence_token_assigned_ = false; | |
34 sequence_token_ = SequencedWorkerPool::SequenceToken(); | |
35 } | 41 } |
36 | 42 |
37 void SequenceCheckerImpl::EnsureSequenceTokenAssigned() const { | 43 void SequenceCheckerImpl::EnsureSequenceTokenAssigned() const { |
38 lock_.AssertAcquired(); | 44 lock_.AssertAcquired(); |
39 if (sequence_token_assigned_) | 45 if (is_assigned_) |
40 return; | 46 return; |
41 | 47 |
42 sequence_token_assigned_ = true; | 48 is_assigned_ = true; |
43 sequence_token_ = SequencedWorkerPool::GetSequenceTokenForCurrentThread(); | 49 sequence_token_ = SequenceToken::GetForCurrentThread(); |
50 sequenced_worker_pool_token_ = | |
51 SequencedWorkerPool::GetSequenceTokenForCurrentThread(); | |
52 | |
53 // SequencedWorkerPool doesn't use SequenceToken and code outside of | |
54 // SequenceWorkerPool doesn't set a SequencedWorkerPool token. | |
55 DCHECK(!sequence_token_.IsValid() || !sequenced_worker_pool_token_.IsValid()); | |
44 } | 56 } |
45 | 57 |
46 } // namespace base | 58 } // namespace base |
OLD | NEW |