OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_THREADING_THREAD_H_ | 5 #ifndef BASE_THREADING_THREAD_H_ |
6 #define BASE_THREADING_THREAD_H_ | 6 #define BASE_THREADING_THREAD_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_loop_proxy.h" | |
15 #include "base/message_loop/timer_slack.h" | 14 #include "base/message_loop/timer_slack.h" |
| 15 #include "base/single_thread_task_runner.h" |
16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 | 19 |
20 class MessagePump; | 20 class MessagePump; |
21 | 21 |
22 // A simple thread abstraction that establishes a MessageLoop on a new thread. | 22 // A simple thread abstraction that establishes a MessageLoop on a new thread. |
23 // The consumer uses the MessageLoop of the thread to cause code to execute on | 23 // The consumer uses the MessageLoop of the thread to cause code to execute on |
24 // the thread. When this object is destroyed the thread is terminated. All | 24 // the thread. When this object is destroyed the thread is terminated. All |
25 // pending tasks queued on the thread's message loop will run to completion | 25 // pending tasks queued on the thread's message loop will run to completion |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 scoped_refptr<MessageLoopProxy> message_loop_proxy() const { | 149 scoped_refptr<MessageLoopProxy> message_loop_proxy() const { |
150 return message_loop_ ? message_loop_->message_loop_proxy() : NULL; | 150 return message_loop_ ? message_loop_->message_loop_proxy() : NULL; |
151 } | 151 } |
152 | 152 |
153 // Returns a TaskRunner for this thread. Use the TaskRunner's PostTask | 153 // Returns a TaskRunner for this thread. Use the TaskRunner's PostTask |
154 // methods to execute code on the thread. Returns NULL if the thread is not | 154 // methods to execute code on the thread. Returns NULL if the thread is not |
155 // running (e.g. before Start or after Stop have been called). Callers can | 155 // running (e.g. before Start or after Stop have been called). Callers can |
156 // hold on to this even after the thread is gone; in this situation, attempts | 156 // hold on to this even after the thread is gone; in this situation, attempts |
157 // to PostTask() will fail. | 157 // to PostTask() will fail. |
158 scoped_refptr<SingleThreadTaskRunner> task_runner() const { | 158 scoped_refptr<SingleThreadTaskRunner> task_runner() const { |
159 return message_loop_proxy(); | 159 return message_loop_->task_runner(); |
160 } | 160 } |
161 | 161 |
162 // Returns the name of this thread (for display in debugger too). | 162 // Returns the name of this thread (for display in debugger too). |
163 const std::string& thread_name() const { return name_; } | 163 const std::string& thread_name() const { return name_; } |
164 | 164 |
165 // The native thread handle. | 165 // The native thread handle. |
166 PlatformThreadHandle thread_handle() { return thread_; } | 166 PlatformThreadHandle thread_handle() { return thread_; } |
167 | 167 |
168 // The thread ID. | 168 // The thread ID. |
169 PlatformThreadId thread_id() const { return thread_id_; } | 169 PlatformThreadId thread_id() const { return thread_id_; } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 std::string name_; | 236 std::string name_; |
237 | 237 |
238 friend void ThreadQuitHelper(); | 238 friend void ThreadQuitHelper(); |
239 | 239 |
240 DISALLOW_COPY_AND_ASSIGN(Thread); | 240 DISALLOW_COPY_AND_ASSIGN(Thread); |
241 }; | 241 }; |
242 | 242 |
243 } // namespace base | 243 } // namespace base |
244 | 244 |
245 #endif // BASE_THREADING_THREAD_H_ | 245 #endif // BASE_THREADING_THREAD_H_ |
OLD | NEW |