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_IMPL_H_
      6 #define BASE_SEQUENCE_CHECKER_IMPL_H_
      7 
      8 #include <memory>
      9 
     10 #include "base/base_export.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/macros.h"
     13 #include "base/synchronization/lock.h"
     14 
     15 namespace base {
     16 
     17 // Real implementation of SequenceChecker for use in debug mode or for temporary
     18 // use in release mode (e.g. to CHECK on a threading issue seen only in the
     19 // wild).
     20 //
     21 // Note: You should almost always use the SequenceChecker class to get the right
     22 // version for your build configuration.
     23 class BASE_EXPORT SequenceCheckerImpl {
     24  public:
     25   SequenceCheckerImpl();
     26   ~SequenceCheckerImpl();
     27 
     28   // Returns true if called in sequence with previous calls to this method and
     29   // the constructor.
     30   bool CalledOnValidSequence() const WARN_UNUSED_RESULT;
     31 
     32   // Unbinds the checker from the currently associated sequence. The checker
     33   // will be re-bound on the next call to CalledOnValidSequence().
     34   void DetachFromSequence();
     35 
     36  private:
     37   class Core;
     38 
     39   // Guards all variables below.
     40   mutable Lock lock_;
     41   mutable std::unique_ptr<Core> core_;
     42 
     43   DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl);
     44 };
     45 
     46 }  // namespace base
     47 
     48 #endif  // BASE_SEQUENCE_CHECKER_IMPL_H_
     49