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.
5 #ifndef BASE_SEQUENCE_CHECKER_IMPL_H_
6 #define BASE_SEQUENCE_CHECKER_IMPL_H_
10 #include "base/base_export.h"
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/synchronization/lock.h"
14 #include "base/thread_annotations.h"
18 // 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
22 // Note: You should almost always use the SequenceChecker class to get the right
23 // version for your build configuration.
24 // Note: This is only a check, not a "lock". It is marked "LOCKABLE" only in
25 // order to support thread_annotations.h.
26 class LOCKABLE BASE_EXPORT SequenceCheckerImpl {
28 SequenceCheckerImpl();
29 ~SequenceCheckerImpl();
31 // Allow move construct/assign. This must be called on |other|'s associated
32 // sequence and assignment can only be made into a SequenceCheckerImpl which
33 // is detached or already associated with the current sequence. This isn't
34 // thread-safe (|this| and |other| shouldn't be in use while this move is
35 // performed). If the assignment was legal, the resulting SequenceCheckerImpl
36 // will be bound to the current sequence and |other| will be detached.
37 SequenceCheckerImpl(SequenceCheckerImpl&& other);
38 SequenceCheckerImpl& operator=(SequenceCheckerImpl&& other);
40 // Returns true if called in sequence with previous calls to this method and
42 bool CalledOnValidSequence() const WARN_UNUSED_RESULT;
44 // Unbinds the checker from the currently associated sequence. The checker
45 // will be re-bound on the next call to CalledOnValidSequence().
46 void DetachFromSequence();
51 // Calls straight to ThreadLocalStorage::HasBeenDestroyed(). Exposed purely
52 // for 'friend' to work.
53 static bool HasThreadLocalStorageBeenDestroyed();
56 mutable std::unique_ptr<Core> core_ GUARDED_BY(lock_);
58 DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl);
63 #endif // BASE_SEQUENCE_CHECKER_IMPL_H_