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

Side by Side Diff: cc/proxy.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Apply code review comments Created 8 years, 1 month 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
« no previous file with comments | « cc/proxy.h ('k') | cc/quad_culler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 11
11 namespace cc { 12 namespace cc {
12 13
13 namespace { 14 Thread* Proxy::mainThread() const
14 #ifndef NDEBUG 15 {
15 bool implThreadIsOverridden = false; 16 return m_mainThread.get();
16 bool s_isMainThreadBlocked = false;
17 #endif
18 Thread* s_mainThread = 0;
19 Thread* s_implThread = 0;
20 } 17 }
21 18
22 void Proxy::setMainThread(Thread* thread) 19 bool Proxy::hasImplThread() const
23 { 20 {
24 s_mainThread = thread; 21 return m_implThread;
25 } 22 }
26 23
27 Thread* Proxy::mainThread() 24 Thread* Proxy::implThread() const
28 { 25 {
29 return s_mainThread; 26 return m_implThread.get();
30 } 27 }
31 28
32 bool Proxy::hasImplThread() 29 Thread* Proxy::currentThread() const
33 { 30 {
34 return s_implThread; 31 if (mainThread() && mainThread()->belongsToCurrentThread())
35 } 32 return mainThread();
36 33 if (implThread() && implThread()->belongsToCurrentThread())
37 void Proxy::setImplThread(Thread* thread) 34 return implThread();
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;
53 return 0; 35 return 0;
54 } 36 }
55 37
56 bool Proxy::isMainThread() 38 bool Proxy::isMainThread() const
57 { 39 {
58 #ifndef NDEBUG 40 #ifndef NDEBUG
59 DCHECK(s_mainThread); 41 DCHECK(mainThread());
60 if (implThreadIsOverridden) 42 if (m_implThreadIsOverridden)
61 return false; 43 return false;
62 return s_mainThread->belongsToCurrentThread(); 44 return mainThread()->belongsToCurrentThread();
63 #else 45 #else
64 return true; 46 return true;
65 #endif 47 #endif
66 } 48 }
67 49
68 bool Proxy::isImplThread() 50 bool Proxy::isImplThread() const
69 { 51 {
70 #ifndef NDEBUG 52 #ifndef NDEBUG
71 if (implThreadIsOverridden) 53 if (m_implThreadIsOverridden)
72 return true; 54 return true;
73 return s_implThread && s_implThread->belongsToCurrentThread(); 55 return implThread() && implThread()->belongsToCurrentThread();
74 #else 56 #else
75 return true; 57 return true;
76 #endif 58 #endif
77 } 59 }
78 60
79 #ifndef NDEBUG 61 #ifndef NDEBUG
80 void Proxy::setCurrentThreadIsImplThread(bool isImplThread) 62 void Proxy::setCurrentThreadIsImplThread(bool isImplThread)
81 { 63 {
82 implThreadIsOverridden = isImplThread; 64 m_implThreadIsOverridden = isImplThread;
83 } 65 }
84 #endif 66 #endif
85 67
86 bool Proxy::isMainThreadBlocked() 68 bool Proxy::isMainThreadBlocked() const
87 { 69 {
88 #ifndef NDEBUG 70 #ifndef NDEBUG
89 return s_isMainThreadBlocked; 71 return m_isMainThreadBlocked;
90 #else 72 #else
91 return true; 73 return true;
92 #endif 74 #endif
93 } 75 }
94 76
95 #ifndef NDEBUG 77 #ifndef NDEBUG
96 void Proxy::setMainThreadBlocked(bool isMainThreadBlocked) 78 void Proxy::setMainThreadBlocked(bool isMainThreadBlocked)
97 { 79 {
98 s_isMainThreadBlocked = isMainThreadBlocked; 80 m_isMainThreadBlocked = isMainThreadBlocked;
99 } 81 }
100 #endif 82 #endif
101 83
102 Proxy::Proxy() 84 Proxy::Proxy(scoped_ptr<Thread> implThread)
85 : m_mainThread(ThreadImpl::createForCurrentThread())
86 , m_implThread(implThread.Pass())
87 #ifndef NDEBUG
88 , m_implThreadIsOverridden(false)
89 , m_isMainThreadBlocked(false)
90 #endif
103 { 91 {
104 DCHECK(isMainThread());
105 } 92 }
106 93
107 Proxy::~Proxy() 94 Proxy::~Proxy()
108 { 95 {
109 DCHECK(isMainThread()); 96 DCHECK(isMainThread());
110 } 97 }
111 98
112 } // namespace cc 99 } // namespace cc
OLDNEW
« no previous file with comments | « cc/proxy.h ('k') | cc/quad_culler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698