OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/proxy.h" | 7 #include "cc/proxy.h" |
8 | 8 |
9 #include "cc/thread.h" | 9 #include "cc/thread.h" |
10 #include "cc/thread_impl.h" | |
11 | 10 |
12 namespace cc { | 11 namespace cc { |
13 | 12 |
14 Thread* Proxy::mainThread() const | 13 namespace { |
15 { | 14 #ifndef NDEBUG |
16 return m_mainThread.get(); | 15 bool implThreadIsOverridden = false; |
| 16 bool s_isMainThreadBlocked = false; |
| 17 #endif |
| 18 Thread* s_mainThread = 0; |
| 19 Thread* s_implThread = 0; |
17 } | 20 } |
18 | 21 |
19 bool Proxy::hasImplThread() const | 22 void Proxy::setMainThread(Thread* thread) |
20 { | 23 { |
21 return m_implThread; | 24 s_mainThread = thread; |
22 } | 25 } |
23 | 26 |
24 Thread* Proxy::implThread() const | 27 Thread* Proxy::mainThread() |
25 { | 28 { |
26 return m_implThread.get(); | 29 return s_mainThread; |
27 } | 30 } |
28 | 31 |
29 Thread* Proxy::currentThread() const | 32 bool Proxy::hasImplThread() |
30 { | 33 { |
31 if (mainThread() && mainThread()->belongsToCurrentThread()) | 34 return s_implThread; |
32 return mainThread(); | 35 } |
33 if (implThread() && implThread()->belongsToCurrentThread()) | 36 |
34 return implThread(); | 37 void Proxy::setImplThread(Thread* thread) |
| 38 { |
| 39 s_implThread = thread; |
| 40 } |
| 41 |
| 42 Thread* Proxy::implThread() |
| 43 { |
| 44 return s_implThread; |
| 45 } |
| 46 |
| 47 Thread* Proxy::currentThread() |
| 48 { |
| 49 if (s_mainThread && s_mainThread->belongsToCurrentThread()) |
| 50 return s_mainThread; |
| 51 if (s_implThread && s_implThread->belongsToCurrentThread()) |
| 52 return s_implThread; |
35 return 0; | 53 return 0; |
36 } | 54 } |
37 | 55 |
38 bool Proxy::isMainThread() const | 56 bool Proxy::isMainThread() |
39 { | 57 { |
40 #ifndef NDEBUG | 58 #ifndef NDEBUG |
41 DCHECK(mainThread()); | 59 DCHECK(s_mainThread); |
42 if (m_implThreadIsOverridden) | 60 if (implThreadIsOverridden) |
43 return false; | 61 return false; |
44 return mainThread()->belongsToCurrentThread(); | 62 return s_mainThread->belongsToCurrentThread(); |
45 #else | 63 #else |
46 return true; | 64 return true; |
47 #endif | 65 #endif |
48 } | 66 } |
49 | 67 |
50 bool Proxy::isImplThread() const | 68 bool Proxy::isImplThread() |
51 { | 69 { |
52 #ifndef NDEBUG | 70 #ifndef NDEBUG |
53 if (m_implThreadIsOverridden) | 71 if (implThreadIsOverridden) |
54 return true; | 72 return true; |
55 return implThread() && implThread()->belongsToCurrentThread(); | 73 return s_implThread && s_implThread->belongsToCurrentThread(); |
56 #else | 74 #else |
57 return true; | 75 return true; |
58 #endif | 76 #endif |
59 } | 77 } |
60 | 78 |
61 #ifndef NDEBUG | 79 #ifndef NDEBUG |
62 void Proxy::setCurrentThreadIsImplThread(bool isImplThread) | 80 void Proxy::setCurrentThreadIsImplThread(bool isImplThread) |
63 { | 81 { |
64 m_implThreadIsOverridden = isImplThread; | 82 implThreadIsOverridden = isImplThread; |
65 } | 83 } |
66 #endif | 84 #endif |
67 | 85 |
68 bool Proxy::isMainThreadBlocked() const | 86 bool Proxy::isMainThreadBlocked() |
69 { | 87 { |
70 #ifndef NDEBUG | 88 #ifndef NDEBUG |
71 return m_isMainThreadBlocked; | 89 return s_isMainThreadBlocked; |
72 #else | 90 #else |
73 return true; | 91 return true; |
74 #endif | 92 #endif |
75 } | 93 } |
76 | 94 |
77 #ifndef NDEBUG | 95 #ifndef NDEBUG |
78 void Proxy::setMainThreadBlocked(bool isMainThreadBlocked) | 96 void Proxy::setMainThreadBlocked(bool isMainThreadBlocked) |
79 { | 97 { |
80 m_isMainThreadBlocked = isMainThreadBlocked; | 98 s_isMainThreadBlocked = isMainThreadBlocked; |
81 } | 99 } |
82 #endif | 100 #endif |
83 | 101 |
84 Proxy::Proxy(scoped_ptr<Thread> implThread) | 102 Proxy::Proxy() |
85 : m_mainThread(ThreadImpl::createForCurrentThread()) | |
86 , m_implThread(implThread.Pass()) | |
87 #ifndef NDEBUG | |
88 , m_implThreadIsOverridden(false) | |
89 , m_isMainThreadBlocked(false) | |
90 #endif | |
91 { | 103 { |
| 104 DCHECK(isMainThread()); |
92 } | 105 } |
93 | 106 |
94 Proxy::~Proxy() | 107 Proxy::~Proxy() |
95 { | 108 { |
96 DCHECK(isMainThread()); | 109 DCHECK(isMainThread()); |
97 } | 110 } |
98 | 111 |
99 } | 112 } |
OLD | NEW |