| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // Returns the message loop for this thread. Use the MessageLoop's | 148 // Returns the message loop for this thread. Use the MessageLoop's |
| 149 // PostTask methods to execute code on the thread. This only returns | 149 // PostTask methods to execute code on the thread. This only returns |
| 150 // non-null after a successful call to Start. After Stop has been called, | 150 // non-null after a successful call to Start. After Stop has been called, |
| 151 // this will return NULL. | 151 // this will return NULL. |
| 152 // | 152 // |
| 153 // NOTE: You must not call this MessageLoop's Quit method directly. Use | 153 // NOTE: You must not call this MessageLoop's Quit method directly. Use |
| 154 // the Thread's Stop method instead. | 154 // the Thread's Stop method instead. |
| 155 // | 155 // |
| 156 MessageLoop* message_loop() const { return message_loop_; } | 156 MessageLoop* message_loop() const { return message_loop_; } |
| 157 | 157 |
| 158 // Returns a MessageLoopProxy for this thread. Use the MessageLoopProxy's | |
| 159 // PostTask methods to execute code on the thread. Returns NULL if the thread | |
| 160 // is not running (e.g. before Start or after Stop have been called). Callers | |
| 161 // can hold on to this even after the thread is gone; in this situation, | |
| 162 // attempts to PostTask() will fail. | |
| 163 // | |
| 164 // Note: This method is deprecated. Callers should call task_runner() instead | |
| 165 // and use the TaskRunner interfaces for safely interfacing with the Thread. | |
| 166 scoped_refptr<MessageLoopProxy> message_loop_proxy() const { | |
| 167 return message_loop_ ? message_loop_->message_loop_proxy() : NULL; | |
| 168 } | |
| 169 | |
| 170 // Returns a TaskRunner for this thread. Use the TaskRunner's PostTask | 158 // Returns a TaskRunner for this thread. Use the TaskRunner's PostTask |
| 171 // methods to execute code on the thread. Returns NULL if the thread is not | 159 // methods to execute code on the thread. Returns NULL if the thread is not |
| 172 // running (e.g. before Start or after Stop have been called). Callers can | 160 // running (e.g. before Start or after Stop have been called). Callers can |
| 173 // hold on to this even after the thread is gone; in this situation, attempts | 161 // hold on to this even after the thread is gone; in this situation, attempts |
| 174 // to PostTask() will fail. | 162 // to PostTask() will fail. |
| 175 scoped_refptr<SingleThreadTaskRunner> task_runner() const { | 163 scoped_refptr<SingleThreadTaskRunner> task_runner() const { |
| 176 return message_loop_->task_runner(); | 164 return message_loop_ ? message_loop_->task_runner() : nullptr; |
| 177 } | 165 } |
| 178 | 166 |
| 179 // Returns the name of this thread (for display in debugger too). | 167 // Returns the name of this thread (for display in debugger too). |
| 180 const std::string& thread_name() const { return name_; } | 168 const std::string& thread_name() const { return name_; } |
| 181 | 169 |
| 182 // The native thread handle. | 170 // The native thread handle. |
| 183 PlatformThreadHandle thread_handle() { return thread_; } | 171 PlatformThreadHandle thread_handle() { return thread_; } |
| 184 | 172 |
| 185 // The thread ID. | 173 // The thread ID. |
| 186 PlatformThreadId thread_id() const; | 174 PlatformThreadId thread_id() const; |
| 187 | 175 |
| 188 // Returns true if the thread has been started, and not yet stopped. | 176 // Returns true if the thread has been started, and not yet stopped. |
| 189 bool IsRunning() const; | 177 bool IsRunning() const; |
| 190 | 178 |
| 191 // Sets the thread priority. The thread must already be started. | |
| 192 void SetPriority(ThreadPriority priority); | |
| 193 | |
| 194 protected: | 179 protected: |
| 195 // Called just prior to starting the message loop | 180 // Called just prior to starting the message loop |
| 196 virtual void Init() {} | 181 virtual void Init() {} |
| 197 | 182 |
| 198 // Called to start the message loop | 183 // Called to start the message loop |
| 199 virtual void Run(MessageLoop* message_loop); | 184 virtual void Run(MessageLoop* message_loop); |
| 200 | 185 |
| 201 // Called just after the message loop ends | 186 // Called just after the message loop ends |
| 202 virtual void CleanUp() {} | 187 virtual void CleanUp() {} |
| 203 | 188 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 scoped_ptr<WaitableEvent> start_event_; | 237 scoped_ptr<WaitableEvent> start_event_; |
| 253 | 238 |
| 254 friend void ThreadQuitHelper(); | 239 friend void ThreadQuitHelper(); |
| 255 | 240 |
| 256 DISALLOW_COPY_AND_ASSIGN(Thread); | 241 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 257 }; | 242 }; |
| 258 | 243 |
| 259 } // namespace base | 244 } // namespace base |
| 260 | 245 |
| 261 #endif // BASE_THREADING_THREAD_H_ | 246 #endif // BASE_THREADING_THREAD_H_ |
| OLD | NEW |