[M94 Dev][Tizen] Fix for errors for generating ninja files
[platform/framework/web/chromium-efl.git] / base / sequence_checker_impl.h
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/synchronization/lock.h"
12 #include "base/thread_annotations.h"
13
14 namespace base {
15 namespace debug {
16 class StackTrace;
17 }
18
19 // Real implementation of SequenceChecker for use in debug mode or for temporary
20 // use in release mode (e.g. to CHECK on a threading issue seen only in the
21 // wild).
22 //
23 // Note: You should almost always use the SequenceChecker class to get the right
24 // version for your build configuration.
25 // Note: This is marked with "context" capability in order to support
26 // thread_annotations.h.
27 class THREAD_ANNOTATION_ATTRIBUTE__(capability("context"))
28     BASE_EXPORT SequenceCheckerImpl {
29  public:
30   static void EnableStackLogging();
31
32   SequenceCheckerImpl();
33
34   // Allow move construct/assign. This must be called on |other|'s associated
35   // sequence and assignment can only be made into a SequenceCheckerImpl which
36   // is detached or already associated with the current sequence. This isn't
37   // thread-safe (|this| and |other| shouldn't be in use while this move is
38   // performed). If the assignment was legal, the resulting SequenceCheckerImpl
39   // will be bound to the current sequence and |other| will be detached.
40   SequenceCheckerImpl(SequenceCheckerImpl&& other);
41   SequenceCheckerImpl& operator=(SequenceCheckerImpl&& other);
42   SequenceCheckerImpl(const SequenceCheckerImpl&) = delete;
43   SequenceCheckerImpl& operator=(const SequenceCheckerImpl&) = delete;
44   ~SequenceCheckerImpl();
45
46   // Returns true if called in sequence with previous calls to this method and
47   // the constructor.
48   // On returning false, if logging is enabled with EnableStackLogging() and
49   // `out_bound_at` is not null, this method allocates a StackTrace and returns
50   // it in the out-parameter, storing inside it the stack from where the failing
51   // SequenceChecker was bound to its sequence. Otherwise, out_bound_at is left
52   // untouched.
53   bool CalledOnValidSequence(std::unique_ptr<debug::StackTrace>* out_bound_at =
54                                  nullptr) const WARN_UNUSED_RESULT;
55
56   // Unbinds the checker from the currently associated sequence. The checker
57   // will be re-bound on the next call to CalledOnValidSequence().
58   void DetachFromSequence();
59
60  private:
61   class Core;
62
63   // Calls straight to ThreadLocalStorage::HasBeenDestroyed(). Exposed purely
64   // for 'friend' to work.
65   static bool HasThreadLocalStorageBeenDestroyed();
66
67   mutable Lock lock_;
68   mutable std::unique_ptr<Core> core_ GUARDED_BY(lock_);
69 };
70
71 }  // namespace base
72
73 #endif  // BASE_SEQUENCE_CHECKER_IMPL_H_