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 #ifndef BASE_SEQUENCE_CHECKER_IMPL_H_ | 5 #ifndef BASE_SEQUENCE_CHECKER_IMPL_H_ |
6 #define BASE_SEQUENCE_CHECKER_IMPL_H_ | 6 #define BASE_SEQUENCE_CHECKER_IMPL_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/base_export.h" | 10 #include "base/base_export.h" |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/sequence_token.h" | |
12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
13 #include "base/threading/sequenced_worker_pool.h" | |
14 #include "base/threading/thread_checker_impl.h" | |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 | 16 |
18 // Real implementation of SequenceChecker for use in debug mode or for temporary | 17 // Real implementation of SequenceChecker for use in debug mode or for temporary |
19 // use in release mode (e.g. to CHECK on a threading issue seen only in the | 18 // use in release mode (e.g. to CHECK on a threading issue seen only in the |
20 // wild). | 19 // wild). |
21 // | 20 // |
22 // Note: You should almost always use the SequenceChecker class to get the right | 21 // Note: You should almost always use the SequenceChecker class to get the right |
23 // version for your build configuration. | 22 // version for your build configuration. |
24 class BASE_EXPORT SequenceCheckerImpl { | 23 class BASE_EXPORT SequenceCheckerImpl { |
25 public: | 24 public: |
26 SequenceCheckerImpl(); | 25 SequenceCheckerImpl(); |
27 ~SequenceCheckerImpl(); | 26 ~SequenceCheckerImpl(); |
28 | 27 |
29 // Returns true if called in sequence with previous calls to this method and | 28 // Returns true if called in sequence with previous calls to this method and |
30 // the constructor. | 29 // the constructor. |
31 bool CalledOnValidSequence() const WARN_UNUSED_RESULT; | 30 bool CalledOnValidSequence() const WARN_UNUSED_RESULT; |
32 | 31 |
33 // Unbinds the checker from the currently associated sequence. The checker | 32 // Unbinds the checker from the currently associated sequence. The checker |
34 // will be re-bound on the next call to CalledOnValidSequence(). | 33 // will be re-bound on the next call to CalledOnValidSequence(). |
35 void DetachFromSequence(); | 34 void DetachFromSequence(); |
36 | 35 |
37 private: | 36 private: |
38 void EnsureSequenceTokenAssigned() const; | 37 class Core; |
39 | 38 |
40 // Guards all variables below. | 39 // Guards all variables below. |
41 mutable Lock lock_; | 40 mutable Lock lock_; |
42 | 41 mutable std::unique_ptr<Core> core_; |
43 // True when the SequenceChecker is bound to a sequence or a thread. | |
44 mutable bool is_assigned_ = false; | |
45 | |
46 mutable SequenceToken sequence_token_; | |
47 | |
48 // TODO(gab): Remove this when SequencedWorkerPool is deprecated in favor of | |
49 // TaskScheduler. crbug.com/622400 | |
50 mutable SequencedWorkerPool::SequenceToken sequenced_worker_pool_token_; | |
51 | |
52 // Used when |sequenced_worker_pool_token_| and |sequence_token_| are invalid. | |
53 ThreadCheckerImpl thread_checker_; | |
54 | 42 |
55 DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl); | 43 DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl); |
56 }; | 44 }; |
57 | 45 |
58 } // namespace base | 46 } // namespace base |
59 | 47 |
60 #endif // BASE_SEQUENCE_CHECKER_IMPL_H_ | 48 #endif // BASE_SEQUENCE_CHECKER_IMPL_H_ |
OLD | NEW |