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" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Returns the message loop for this thread. Use the MessageLoop's | 131 // Returns the message loop for this thread. Use the MessageLoop's |
132 // PostTask methods to execute code on the thread. This only returns | 132 // PostTask methods to execute code on the thread. This only returns |
133 // non-null after a successful call to Start. After Stop has been called, | 133 // non-null after a successful call to Start. After Stop has been called, |
134 // this will return NULL. | 134 // this will return NULL. |
135 // | 135 // |
136 // NOTE: You must not call this MessageLoop's Quit method directly. Use | 136 // NOTE: You must not call this MessageLoop's Quit method directly. Use |
137 // the Thread's Stop method instead. | 137 // the Thread's Stop method instead. |
138 // | 138 // |
139 MessageLoop* message_loop() const { return message_loop_; } | 139 MessageLoop* message_loop() const { return message_loop_; } |
140 | 140 |
141 // Returns a MessageLoopProxy for this thread. Use the MessageLoopProxy's | 141 // Returns a MessageLoopProxy for this thread. Use the MessageLoopProxy's |
142 // PostTask methods to execute code on the thread. This only returns | 142 // PostTask methods to execute code on the thread. Returns NULL if the thread |
143 // non-NULL after a successful call to Start. After Stop has been called, | 143 // is not running (e.g. before Start or after Stop have been called). Callers |
144 // this will return NULL. Callers can hold on to this even after the thread | 144 // can hold on to this even after the thread is gone; in this situation, |
145 // is gone. | 145 // attempts to PostTask() will fail. |
| 146 // |
| 147 // Note: This method is deprecated. Callers should call task_runner() instead |
| 148 // and use the TaskRunner interfaces for safely interfacing with the Thread. |
146 scoped_refptr<MessageLoopProxy> message_loop_proxy() const { | 149 scoped_refptr<MessageLoopProxy> message_loop_proxy() const { |
147 return message_loop_ ? message_loop_->message_loop_proxy() : NULL; | 150 return message_loop_ ? message_loop_->message_loop_proxy() : NULL; |
148 } | 151 } |
149 | 152 |
| 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 |
| 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 |
| 157 // to PostTask() will fail. |
| 158 scoped_refptr<SingleThreadTaskRunner> task_runner() const { |
| 159 return message_loop_proxy(); |
| 160 } |
| 161 |
150 // Returns the name of this thread (for display in debugger too). | 162 // Returns the name of this thread (for display in debugger too). |
151 const std::string& thread_name() const { return name_; } | 163 const std::string& thread_name() const { return name_; } |
152 | 164 |
153 // The native thread handle. | 165 // The native thread handle. |
154 PlatformThreadHandle thread_handle() { return thread_; } | 166 PlatformThreadHandle thread_handle() { return thread_; } |
155 | 167 |
156 // The thread ID. | 168 // The thread ID. |
157 PlatformThreadId thread_id() const { return thread_id_; } | 169 PlatformThreadId thread_id() const { return thread_id_; } |
158 | 170 |
159 // Returns true if the thread has been started, and not yet stopped. | 171 // Returns true if the thread has been started, and not yet stopped. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 std::string name_; | 236 std::string name_; |
225 | 237 |
226 friend void ThreadQuitHelper(); | 238 friend void ThreadQuitHelper(); |
227 | 239 |
228 DISALLOW_COPY_AND_ASSIGN(Thread); | 240 DISALLOW_COPY_AND_ASSIGN(Thread); |
229 }; | 241 }; |
230 | 242 |
231 } // namespace base | 243 } // namespace base |
232 | 244 |
233 #endif // BASE_THREADING_THREAD_H_ | 245 #endif // BASE_THREADING_THREAD_H_ |
OLD | NEW |