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 #include "CCThreadImpl.h" | 6 #include "CCThreadImpl.h" |
7 | 7 |
8 #include "CCCompletionEvent.h" | 8 #include "CCCompletionEvent.h" |
9 #include <public/Platform.h> | 9 #include <public/Platform.h> |
10 #include <public/WebThread.h> | 10 #include <public/WebThread.h> |
11 | 11 |
12 using WebCore::CCThread; | 12 using WebCore::CCThread; |
13 using WebCore::CCCompletionEvent; | 13 using WebCore::CCCompletionEvent; |
14 | 14 |
15 namespace WebKit { | 15 namespace WebKit { |
16 | 16 |
17 // Task that, when runs, places the current thread ID into the provided | 17 // Task that, when runs, places the current thread ID into the provided |
18 // pointer and signals a completion event. | 18 // pointer and signals a completion event. |
19 // | 19 // |
20 // Does not provide a PassOwnPtr<GetThreadIDTask>::create method because | 20 // Does not provide a PassOwnPtr<GetThreadIDTask>::create method because |
21 // the resulting object is always handed into a WebThread, which does not unders
tand | 21 // the resulting object is always handed into a WebThread, which does not unders
tand |
22 // PassOwnPtrs. | 22 // PassOwnPtrs. |
23 class GetThreadIDTask : public WebThread::Task { | 23 class GetThreadIDTask : public WebThread::Task { |
24 public: | 24 public: |
25 GetThreadIDTask(ThreadIdentifier* result, CCCompletionEvent* completion) | 25 GetThreadIDTask(base::PlatformThreadId* result, CCCompletionEvent* completio
n) |
26 : m_completion(completion) | 26 : m_completion(completion) |
27 , m_result(result) { } | 27 , m_result(result) { } |
28 | 28 |
29 virtual ~GetThreadIDTask() { } | 29 virtual ~GetThreadIDTask() { } |
30 | 30 |
31 virtual void run() | 31 virtual void run() |
32 { | 32 { |
33 *m_result = currentThread(); | 33 *m_result = base::PlatformThread::CurrentId(); |
34 m_completion->signal(); | 34 m_completion->signal(); |
35 } | 35 } |
36 | 36 |
37 private: | 37 private: |
38 CCCompletionEvent* m_completion; | 38 CCCompletionEvent* m_completion; |
39 ThreadIdentifier* m_result; | 39 base::PlatformThreadId* m_result; |
40 }; | 40 }; |
41 | 41 |
42 // General adapter from a CCThread::Task to a WebThread::Task. | 42 // General adapter from a CCThread::Task to a WebThread::Task. |
43 class CCThreadTaskAdapter : public WebThread::Task { | 43 class CCThreadTaskAdapter : public WebThread::Task { |
44 public: | 44 public: |
45 CCThreadTaskAdapter(PassOwnPtr<CCThread::Task> task) : m_task(task) { } | 45 CCThreadTaskAdapter(PassOwnPtr<CCThread::Task> task) : m_task(task) { } |
46 | 46 |
47 virtual ~CCThreadTaskAdapter() { } | 47 virtual ~CCThreadTaskAdapter() { } |
48 | 48 |
49 virtual void run() | 49 virtual void run() |
50 { | 50 { |
51 m_task->performTask(); | 51 m_task->performTask(); |
52 } | 52 } |
53 | 53 |
54 private: | 54 private: |
55 OwnPtr<CCThread::Task> m_task; | 55 OwnPtr<CCThread::Task> m_task; |
56 }; | 56 }; |
57 | 57 |
58 PassOwnPtr<CCThread> CCThreadImpl::create(WebThread* thread) | 58 PassOwnPtr<CCThread> CCThreadImpl::createForCurrentThread() |
59 { | 59 { |
60 return adoptPtr(new CCThreadImpl(thread)); | 60 return adoptPtr(new CCThreadImpl(Platform::current()->currentThread(), true)
); |
| 61 } |
| 62 |
| 63 PassOwnPtr<CCThread> CCThreadImpl::createForDifferentThread(WebThread* thread) |
| 64 { |
| 65 return adoptPtr(new CCThreadImpl(thread, false)); |
61 } | 66 } |
62 | 67 |
63 CCThreadImpl::~CCThreadImpl() | 68 CCThreadImpl::~CCThreadImpl() |
64 { | 69 { |
65 } | 70 } |
66 | 71 |
67 void CCThreadImpl::postTask(PassOwnPtr<CCThread::Task> task) | 72 void CCThreadImpl::postTask(PassOwnPtr<CCThread::Task> task) |
68 { | 73 { |
69 m_thread->postTask(new CCThreadTaskAdapter(task)); | 74 m_thread->postTask(new CCThreadTaskAdapter(task)); |
70 } | 75 } |
71 | 76 |
72 void CCThreadImpl::postDelayedTask(PassOwnPtr<CCThread::Task> task, long long de
layMs) | 77 void CCThreadImpl::postDelayedTask(PassOwnPtr<CCThread::Task> task, long long de
layMs) |
73 { | 78 { |
74 m_thread->postDelayedTask(new CCThreadTaskAdapter(task), delayMs); | 79 m_thread->postDelayedTask(new CCThreadTaskAdapter(task), delayMs); |
75 } | 80 } |
76 | 81 |
77 ThreadIdentifier CCThreadImpl::threadID() const | 82 base::PlatformThreadId CCThreadImpl::threadID() const |
78 { | 83 { |
79 return m_threadID; | 84 return m_threadID; |
80 } | 85 } |
81 | 86 |
82 CCThreadImpl::CCThreadImpl(WebThread* thread) | 87 CCThreadImpl::CCThreadImpl(WebThread* thread, bool currentThread) |
83 : m_thread(thread) | 88 : m_thread(thread) |
84 { | 89 { |
85 if (thread == WebKit::Platform::current()->currentThread()) { | 90 if (currentThread) { |
86 m_threadID = currentThread(); | 91 m_threadID = base::PlatformThread::CurrentId(); |
87 return; | 92 return; |
88 } | 93 } |
89 | 94 |
90 // Get the threadId for the newly-created thread by running a task | 95 // Get the threadId for the newly-created thread by running a task |
91 // on that thread, blocking on the result. | 96 // on that thread, blocking on the result. |
92 m_threadID = currentThread(); | |
93 CCCompletionEvent completion; | 97 CCCompletionEvent completion; |
94 m_thread->postTask(new GetThreadIDTask(&m_threadID, &completion)); | 98 m_thread->postTask(new GetThreadIDTask(&m_threadID, &completion)); |
95 completion.wait(); | 99 completion.wait(); |
96 } | 100 } |
97 | 101 |
98 } // namespace WebKit | 102 } // namespace WebKit |
OLD | NEW |