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

Side by Side Diff: cc/scoped_thread_proxy.h

Issue 11196014: Revert "cc: Switch to Chromium DCHECKs LOGs" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/scoped_texture.cc ('k') | cc/scrollbar_layer.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 #ifndef CCScopedThreadProxy_h 5 #ifndef CCScopedThreadProxy_h
6 #define CCScopedThreadProxy_h 6 #define CCScopedThreadProxy_h
7 7
8 #include "CCThreadTask.h" 8 #include "CCThreadTask.h"
9 #include "base/logging.h"
10 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
11 #include <wtf/OwnPtr.h> 10 #include <wtf/OwnPtr.h>
12 #include <wtf/PassOwnPtr.h> 11 #include <wtf/PassOwnPtr.h>
13 #include <wtf/ThreadSafeRefCounted.h> 12 #include <wtf/ThreadSafeRefCounted.h>
14 13
15 namespace cc { 14 namespace cc {
16 15
17 // This class is a proxy used to post tasks to an target thread from any other t hread. The proxy may be shut down at 16 // This class is a proxy used to post tasks to an target thread from any other t hread. The proxy may be shut down at
18 // any point from the target thread after which no more tasks posted to the prox y will run. In other words, all 17 // any point from the target thread after which no more tasks posted to the prox y will run. In other words, all
19 // tasks posted via a proxy are scoped to the lifecycle of the proxy. Use this w hen posting tasks to an object that 18 // tasks posted via a proxy are scoped to the lifecycle of the proxy. Use this w hen posting tasks to an object that
20 // might die with tasks in flight. 19 // might die with tasks in flight.
21 // 20 //
22 // The proxy must be created and shut down from the target thread, tasks may be posted from any thread. 21 // The proxy must be created and shut down from the target thread, tasks may be posted from any thread.
23 // 22 //
24 // Implementation note: Unlike ScopedRunnableMethodFactory in Chromium, pending tasks are not cancelled by actually 23 // Implementation note: Unlike ScopedRunnableMethodFactory in Chromium, pending tasks are not cancelled by actually
25 // destroying the proxy. Instead each pending task holds a reference to the prox y to avoid maintaining an explicit 24 // destroying the proxy. Instead each pending task holds a reference to the prox y to avoid maintaining an explicit
26 // list of outstanding tasks. 25 // list of outstanding tasks.
27 class CCScopedThreadProxy : public ThreadSafeRefCounted<CCScopedThreadProxy> { 26 class CCScopedThreadProxy : public ThreadSafeRefCounted<CCScopedThreadProxy> {
28 public: 27 public:
29 static PassRefPtr<CCScopedThreadProxy> create(CCThread* targetThread) 28 static PassRefPtr<CCScopedThreadProxy> create(CCThread* targetThread)
30 { 29 {
31 DCHECK(base::PlatformThread::CurrentId() == targetThread->threadID()); 30 ASSERT(base::PlatformThread::CurrentId() == targetThread->threadID());
32 return adoptRef(new CCScopedThreadProxy(targetThread)); 31 return adoptRef(new CCScopedThreadProxy(targetThread));
33 } 32 }
34 33
35 ~CCScopedThreadProxy(); 34 ~CCScopedThreadProxy();
36 35
37 // Can be called from any thread. Posts a task to the target thread that run s unless 36 // Can be called from any thread. Posts a task to the target thread that run s unless
38 // shutdown() is called before it runs. 37 // shutdown() is called before it runs.
39 void postTask(PassOwnPtr<CCThread::Task> task) 38 void postTask(PassOwnPtr<CCThread::Task> task)
40 { 39 {
41 ref(); 40 ref();
42 m_targetThread->postTask(createCCThreadTask(this, &CCScopedThreadProxy:: runTaskIfNotShutdown, task)); 41 m_targetThread->postTask(createCCThreadTask(this, &CCScopedThreadProxy:: runTaskIfNotShutdown, task));
43 } 42 }
44 43
45 void shutdown() 44 void shutdown()
46 { 45 {
47 DCHECK(base::PlatformThread::CurrentId() == m_targetThread->threadID()); 46 ASSERT(base::PlatformThread::CurrentId() == m_targetThread->threadID());
48 DCHECK(!m_shutdown); 47 ASSERT(!m_shutdown);
49 m_shutdown = true; 48 m_shutdown = true;
50 } 49 }
51 50
52 private: 51 private:
53 explicit CCScopedThreadProxy(CCThread* targetThread); 52 explicit CCScopedThreadProxy(CCThread* targetThread);
54 53
55 void runTaskIfNotShutdown(PassOwnPtr<CCThread::Task> popTask) 54 void runTaskIfNotShutdown(PassOwnPtr<CCThread::Task> popTask)
56 { 55 {
57 OwnPtr<CCThread::Task> task = popTask; 56 OwnPtr<CCThread::Task> task = popTask;
58 // If our shutdown flag is set, it's possible that m_targetThread has al ready been destroyed so don't 57 // If our shutdown flag is set, it's possible that m_targetThread has al ready been destroyed so don't
59 // touch it. 58 // touch it.
60 if (m_shutdown) { 59 if (m_shutdown) {
61 deref(); 60 deref();
62 return; 61 return;
63 } 62 }
64 DCHECK(base::PlatformThread::CurrentId() == m_targetThread->threadID()); 63 ASSERT(base::PlatformThread::CurrentId() == m_targetThread->threadID());
65 task->performTask(); 64 task->performTask();
66 deref(); 65 deref();
67 } 66 }
68 67
69 CCThread* m_targetThread; 68 CCThread* m_targetThread;
70 bool m_shutdown; // Only accessed on the target thread 69 bool m_shutdown; // Only accessed on the target thread
71 }; 70 };
72 71
73 } 72 }
74 73
75 #endif 74 #endif
OLDNEW
« no previous file with comments | « cc/scoped_texture.cc ('k') | cc/scrollbar_layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698