Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: base/sequence_checker.h

Issue 2165663003: TaskScheduler: Add SequenceToken and ScopedSetSequenceTokenForCurrentThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_H_ 5 #ifndef BASE_SEQUENCE_CHECKER_H_
6 #define BASE_SEQUENCE_CHECKER_H_ 6 #define BASE_SEQUENCE_CHECKER_H_
7 7
8 // See comments for the similar block in thread_checker.h. 8 // See comments for the similar block in thread_checker.h.
9 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 9 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
10 #define ENABLE_SEQUENCE_CHECKER 1 10 #define ENABLE_SEQUENCE_CHECKER 1
11 #else 11 #else
12 #define ENABLE_SEQUENCE_CHECKER 0 12 #define ENABLE_SEQUENCE_CHECKER 0
13 #endif 13 #endif
14 14
15 #include "base/sequence_checker_impl.h" 15 #include "base/sequence_checker_impl.h"
16 16
17 namespace base { 17 namespace base {
18 18
19 // Do nothing implementation, for use in release mode. 19 // Do nothing implementation, for use in release mode.
20 // 20 //
21 // Note: You should almost always use the SequenceChecker class to get 21 // Note: You should almost always use the SequenceChecker class to get
22 // the right version for your build configuration. 22 // the right version for your build configuration.
23 class SequenceCheckerDoNothing { 23 class SequenceCheckerDoNothing {
24 public: 24 public:
25 bool CalledOnValidSequencedThread() const { 25 bool CalledOnValidSequencedThread() const {
gab 2016/07/28 15:16:41 Just had a post-commit thought when looking at oth
fdoray 2016/07/28 18:10:04 I agree! Working on a CL that makes this change.
26 return true; 26 return true;
27 } 27 }
28 28
29 void DetachFromSequence() {} 29 void DetachFromSequence() {}
30 }; 30 };
31 31
32 // SequenceChecker is a helper class used to help verify that some 32 // SequenceChecker is a helper class to verify that calls to some methods of a
33 // methods of a class are called in sequence -- that is, called from 33 // class are sequenced. Calls are sequenced when they are issued:
34 // the same SequencedTaskRunner. It is a generalization of 34 // - From tasks posted to SequencedTaskRunners or SingleThreadTaskRunners bound
35 // ThreadChecker; see comments in sequence_checker_impl.h for details. 35 // to the same sequence, or,
36 // - From a single thread outside of any task.
gab 2016/07/26 20:49:48 I find this last statement confusing, MessageLoop
fdoray 2016/07/28 18:10:04 I think we don't plan to support child single-thre
gab 2016/07/29 13:31:37 On 2016/07/28 18:10:04, fdoray wrote:
36 // 37 //
37 // Example: 38 // Example:
38 // class MyClass { 39 // class MyClass {
39 // public: 40 // public:
40 // void Foo() { 41 // void Foo() {
41 // DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 42 // DCHECK(sequence_checker_.CalledOnValidSequencedThread());
42 // ... (do stuff) ... 43 // ... (do stuff) ...
43 // } 44 // }
44 // 45 //
45 // private: 46 // private:
46 // SequenceChecker sequence_checker_; 47 // SequenceChecker sequence_checker_;
47 // } 48 // }
48 // 49 //
49 // In Release mode, CalledOnValidSequencedThread() will always return true. 50 // In Release mode, CalledOnValidSequencedThread() will always return true.
50 #if ENABLE_SEQUENCE_CHECKER 51 #if ENABLE_SEQUENCE_CHECKER
51 class SequenceChecker : public SequenceCheckerImpl { 52 class SequenceChecker : public SequenceCheckerImpl {
52 }; 53 };
53 #else 54 #else
54 class SequenceChecker : public SequenceCheckerDoNothing { 55 class SequenceChecker : public SequenceCheckerDoNothing {
55 }; 56 };
56 #endif // ENABLE_SEQUENCE_CHECKER 57 #endif // ENABLE_SEQUENCE_CHECKER
57 58
58 #undef ENABLE_SEQUENCE_CHECKER 59 #undef ENABLE_SEQUENCE_CHECKER
59 60
60 } // namespace base 61 } // namespace base
61 62
62 #endif // BASE_SEQUENCE_CHECKER_H_ 63 #endif // BASE_SEQUENCE_CHECKER_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/sequence_checker_impl.h » ('j') | base/sequence_checker_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698