OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #include "CCProxy.h" | |
8 | |
9 #include "CCThreadTask.h" | |
10 | |
11 using namespace WTF; | |
12 | |
13 namespace cc { | |
14 | |
15 namespace { | |
16 #ifndef NDEBUG | |
17 bool implThreadIsOverridden = false; | |
18 bool s_isMainThreadBlocked = false; | |
19 base::PlatformThreadId threadIDOverridenToBeImplThread; | |
20 #endif | |
21 CCThread* s_mainThread = 0; | |
22 CCThread* s_implThread = 0; | |
23 } | |
24 | |
25 void CCProxy::setMainThread(CCThread* thread) | |
26 { | |
27 s_mainThread = thread; | |
28 } | |
29 | |
30 CCThread* CCProxy::mainThread() | |
31 { | |
32 return s_mainThread; | |
33 } | |
34 | |
35 bool CCProxy::hasImplThread() | |
36 { | |
37 return s_implThread; | |
38 } | |
39 | |
40 void CCProxy::setImplThread(CCThread* thread) | |
41 { | |
42 s_implThread = thread; | |
43 } | |
44 | |
45 CCThread* CCProxy::implThread() | |
46 { | |
47 return s_implThread; | |
48 } | |
49 | |
50 CCThread* CCProxy::currentThread() | |
51 { | |
52 base::PlatformThreadId currentThreadIdentifier = base::PlatformThread::Curre
ntId(); | |
53 if (s_mainThread && s_mainThread->threadID() == currentThreadIdentifier) | |
54 return s_mainThread; | |
55 if (s_implThread && s_implThread->threadID() == currentThreadIdentifier) | |
56 return s_implThread; | |
57 return 0; | |
58 } | |
59 | |
60 #ifndef NDEBUG | |
61 bool CCProxy::isMainThread() | |
62 { | |
63 ASSERT(s_mainThread); | |
64 if (implThreadIsOverridden && base::PlatformThread::CurrentId() == threadIDO
verridenToBeImplThread) | |
65 return false; | |
66 return base::PlatformThread::CurrentId() == s_mainThread->threadID(); | |
67 } | |
68 | |
69 bool CCProxy::isImplThread() | |
70 { | |
71 base::PlatformThreadId implThreadID = s_implThread ? s_implThread->threadID(
) : 0; | |
72 if (implThreadIsOverridden && base::PlatformThread::CurrentId() == threadIDO
verridenToBeImplThread) | |
73 return true; | |
74 return base::PlatformThread::CurrentId() == implThreadID; | |
75 } | |
76 | |
77 void CCProxy::setCurrentThreadIsImplThread(bool isImplThread) | |
78 { | |
79 implThreadIsOverridden = isImplThread; | |
80 if (isImplThread) | |
81 threadIDOverridenToBeImplThread = base::PlatformThread::CurrentId(); | |
82 } | |
83 | |
84 bool CCProxy::isMainThreadBlocked() | |
85 { | |
86 return s_isMainThreadBlocked; | |
87 } | |
88 | |
89 void CCProxy::setMainThreadBlocked(bool isMainThreadBlocked) | |
90 { | |
91 s_isMainThreadBlocked = isMainThreadBlocked; | |
92 } | |
93 #endif | |
94 | |
95 CCProxy::CCProxy() | |
96 { | |
97 ASSERT(isMainThread()); | |
98 } | |
99 | |
100 CCProxy::~CCProxy() | |
101 { | |
102 ASSERT(isMainThread()); | |
103 } | |
104 | |
105 } | |
OLD | NEW |