Home | History | Annotate | Download | only in base
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef BASE_SEQUENCE_CHECKER_H_
      6 #define BASE_SEQUENCE_CHECKER_H_
      7 
      8 #include "base/sequence_checker_impl.h"
      9 
     10 namespace base {
     11 
     12 // Do nothing implementation, for use in release mode.
     13 //
     14 // Note: You should almost always use the SequenceChecker class to get
     15 // the right version for your build configuration.
     16 class SequenceCheckerDoNothing {
     17  public:
     18   bool CalledOnValidSequence() const { return true; }
     19 
     20   void DetachFromSequence() {}
     21 };
     22 
     23 // SequenceChecker is a helper class to verify that calls to some methods of a
     24 // class are sequenced. Calls are sequenced when they are issued:
     25 // - From tasks posted to SequencedTaskRunners or SingleThreadTaskRunners bound
     26 //   to the same sequence, or,
     27 // - From a single thread outside of any task.
     28 //
     29 // Example:
     30 // class MyClass {
     31 //  public:
     32 //   void Foo() {
     33 //     DCHECK(sequence_checker_.CalledOnValidSequence());
     34 //     ... (do stuff) ...
     35 //   }
     36 //
     37 //  private:
     38 //   SequenceChecker sequence_checker_;
     39 // }
     40 //
     41 // In Release mode, CalledOnValidSequence() will always return true.
     42 #if DCHECK_IS_ON()
     43 class SequenceChecker : public SequenceCheckerImpl {
     44 };
     45 #else
     46 class SequenceChecker : public SequenceCheckerDoNothing {
     47 };
     48 #endif  // DCHECK_IS_ON()
     49 
     50 }  // namespace base
     51 
     52 #endif  // BASE_SEQUENCE_CHECKER_H_
     53