Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: cc/trees/thread_verifier.h

Issue 1411663002: cc: Split Proxy to eliminate unnecessary dependencies on the impl side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 CC_TREES_THREAD_VERIFIER_H_
6 #define CC_TREES_THREAD_VERIFIER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/platform_thread.h"
15 #include "base/time/time.h"
16 #include "base/values.h"
17 #include "cc/base/cc_export.h"
18
19 namespace base {
20 namespace trace_event {
21 class TracedValue;
22 }
23 class SingleThreadTaskRunner;
24 }
25
26 namespace cc {
27 class BlockingTaskRunner;
28
29 // Class responsible for controlling access to the main and impl task runners.
30 // Useful for assertion checks.
31 class CC_EXPORT ThreadVerifier {
vmpstr 2015/10/16 18:42:26 I'd maybe prefer to call this something like TaskR
Khushal 2015/10/17 00:06:30 Done. That name makes much more sense.
32 public:
33 base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
34 bool HasImplThread() const;
35 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
36
37 // Debug hooks.
38 bool IsMainThread() const;
39 bool IsImplThread() const;
40 bool IsMainThreadBlocked() const;
41 #if DCHECK_IS_ON()
42 void SetMainThreadBlocked(bool is_main_thread_blocked);
43 void SetCurrentThreadIsImplThread(bool is_impl_thread);
44 #endif
45
46 virtual ~ThreadVerifier();
47
48 BlockingTaskRunner* blocking_main_thread_task_runner() const {
49 return blocking_main_thread_task_runner_.get();
50 }
51
52 ThreadVerifier(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
53 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
54
55 protected:
56 friend class DebugScopedSetImplThread;
57 friend class DebugScopedSetMainThread;
58 friend class DebugScopedSetMainThreadBlocked;
59
60 private:
61 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
62 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
63 scoped_ptr<BlockingTaskRunner> blocking_main_thread_task_runner_;
64
65 #if DCHECK_IS_ON()
66 const base::PlatformThreadId main_thread_id_;
67 bool impl_thread_is_overridden_;
68 bool is_main_thread_blocked_;
69 #endif
70
71 DISALLOW_COPY_AND_ASSIGN(ThreadVerifier);
72 };
73
74 #if DCHECK_IS_ON()
75 class DebugScopedSetMainThreadBlocked {
76 public:
77 explicit DebugScopedSetMainThreadBlocked(ThreadVerifier* thread_verifier)
78 : thread_verifier_(thread_verifier) {
79 DCHECK(!thread_verifier_->IsMainThreadBlocked());
80 thread_verifier_->SetMainThreadBlocked(true);
81 }
82 ~DebugScopedSetMainThreadBlocked() {
83 DCHECK(thread_verifier_->IsMainThreadBlocked());
84 thread_verifier_->SetMainThreadBlocked(false);
85 }
86
87 private:
88 ThreadVerifier* thread_verifier_;
89 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
90 };
91 #else
92 class DebugScopedSetMainThreadBlocked {
93 public:
94 explicit DebugScopedSetMainThreadBlocked(ThreadVerifier* thread_verifier) {}
95 ~DebugScopedSetMainThreadBlocked() {}
96
97 private:
98 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
99 };
100 #endif
101
102 } // namespace cc
103
104 #endif // CC_TREES_THREAD_VERIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698