blob: ad0182825c24805548f05972c7c04e6813688bc7 [file] [log] [blame]
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +09001// 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.
4
5#ifndef BASE_SEQUENCE_CHECKER_H_
6#define BASE_SEQUENCE_CHECKER_H_
7
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +09008// See comments for the similar block in thread_checker.h.
9#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
10#define ENABLE_SEQUENCE_CHECKER 1
11#else
12#define ENABLE_SEQUENCE_CHECKER 0
13#endif
14
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090015#include "base/sequence_checker_impl.h"
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090016
17namespace base {
18
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090019// Do nothing implementation, for use in release mode.
20//
21// Note: You should almost always use the SequenceChecker class to get
22// the right version for your build configuration.
23class SequenceCheckerDoNothing {
24 public:
tommycli@chromium.org623e16c2013-07-31 04:26:40 +090025 bool CalledOnValidSequencedThread() const {
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090026 return true;
27 }
28
tommycli@chromium.org623e16c2013-07-31 04:26:40 +090029 void DetachFromSequence() {}
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090030};
31
32// SequenceChecker is a helper class used to help verify that some
33// methods of a class are called in sequence -- that is, called from
34// the same SequencedTaskRunner. It is a generalization of
35// ThreadChecker; see comments in sequence_checker_impl.h for details.
36//
37// Example:
38// class MyClass {
39// public:
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090040// void Foo() {
thestig@chromium.org750aa9e2013-09-27 10:21:28 +090041// DCHECK(sequence_checker_.CalledOnValidSequencedThread());
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090042// ... (do stuff) ...
43// }
44//
45// private:
46// SequenceChecker sequence_checker_;
47// }
48//
thestig@chromium.orge2cdbbb2014-02-16 05:47:58 +090049// In Release mode, CalledOnValidSequencedThread() will always return true.
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090050#if ENABLE_SEQUENCE_CHECKER
51class SequenceChecker : public SequenceCheckerImpl {
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090052};
53#else
54class SequenceChecker : public SequenceCheckerDoNothing {
akalin@chromium.org4fb2deb2012-12-28 04:58:00 +090055};
56#endif // ENABLE_SEQUENCE_CHECKER
57
58#undef ENABLE_SEQUENCE_CHECKER
59
60} // namespace base
61
62#endif // BASE_SEQUENCE_CHECKER_H_