| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_THREAD_H_ | 5 #ifndef BASE_THREAD_H_ |
| 6 #define BASE_THREAD_H_ | 6 #define BASE_THREAD_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/message_loop_proxy.h" |
| 11 #include "base/platform_thread.h" | 12 #include "base/platform_thread.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 // A simple thread abstraction that establishes a MessageLoop on a new thread. | 16 // A simple thread abstraction that establishes a MessageLoop on a new thread. |
| 16 // The consumer uses the MessageLoop of the thread to cause code to execute on | 17 // The consumer uses the MessageLoop of the thread to cause code to execute on |
| 17 // the thread. When this object is destroyed the thread is terminated. All | 18 // the thread. When this object is destroyed the thread is terminated. All |
| 18 // pending tasks queued on the thread's message loop will run to completion | 19 // pending tasks queued on the thread's message loop will run to completion |
| 19 // before the thread is terminated. | 20 // before the thread is terminated. |
| 20 // | 21 // |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Returns the message loop for this thread. Use the MessageLoop's | 98 // Returns the message loop for this thread. Use the MessageLoop's |
| 98 // PostTask methods to execute code on the thread. This only returns | 99 // PostTask methods to execute code on the thread. This only returns |
| 99 // non-null after a successful call to Start. After Stop has been called, | 100 // non-null after a successful call to Start. After Stop has been called, |
| 100 // this will return NULL. | 101 // this will return NULL. |
| 101 // | 102 // |
| 102 // NOTE: You must not call this MessageLoop's Quit method directly. Use | 103 // NOTE: You must not call this MessageLoop's Quit method directly. Use |
| 103 // the Thread's Stop method instead. | 104 // the Thread's Stop method instead. |
| 104 // | 105 // |
| 105 MessageLoop* message_loop() const { return message_loop_; } | 106 MessageLoop* message_loop() const { return message_loop_; } |
| 106 | 107 |
| 108 // Returns a MessageLoopProxy for this thread. Use the MessageLoopProxy's |
| 109 // PostTask methods to execute code on the thread. This only returns |
| 110 // non-null after a successful call to Start. After Stop has been called, |
| 111 // this will return NULL. Callers can hold on to this even after the thread |
| 112 // is gone. |
| 113 // TODO(sanjeevr): Look into merging MessageLoop and MessageLoopProxy. |
| 114 scoped_refptr<MessageLoopProxy> message_loop_proxy() { |
| 115 return message_loop_proxy_; |
| 116 } |
| 117 |
| 107 // Set the name of this thread (for display in debugger too). | 118 // Set the name of this thread (for display in debugger too). |
| 108 const std::string &thread_name() { return name_; } | 119 const std::string &thread_name() { return name_; } |
| 109 | 120 |
| 110 // The native thread handle. | 121 // The native thread handle. |
| 111 PlatformThreadHandle thread_handle() { return thread_; } | 122 PlatformThreadHandle thread_handle() { return thread_; } |
| 112 | 123 |
| 113 // The thread ID. | 124 // The thread ID. |
| 114 PlatformThreadId thread_id() const { return thread_id_; } | 125 PlatformThreadId thread_id() const { return thread_id_; } |
| 115 | 126 |
| 116 // Returns true if the thread has been started, and not yet stopped. | 127 // Returns true if the thread has been started, and not yet stopped. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 struct StartupData; | 166 struct StartupData; |
| 156 StartupData* startup_data_; | 167 StartupData* startup_data_; |
| 157 | 168 |
| 158 // The thread's handle. | 169 // The thread's handle. |
| 159 PlatformThreadHandle thread_; | 170 PlatformThreadHandle thread_; |
| 160 | 171 |
| 161 // The thread's message loop. Valid only while the thread is alive. Set | 172 // The thread's message loop. Valid only while the thread is alive. Set |
| 162 // by the created thread. | 173 // by the created thread. |
| 163 MessageLoop* message_loop_; | 174 MessageLoop* message_loop_; |
| 164 | 175 |
| 176 // A MessageLoopProxy implementation that targets this thread. This can |
| 177 // outlive the thread. |
| 178 scoped_refptr<MessageLoopProxy> message_loop_proxy_; |
| 179 |
| 165 // Our thread's ID. | 180 // Our thread's ID. |
| 166 PlatformThreadId thread_id_; | 181 PlatformThreadId thread_id_; |
| 167 | 182 |
| 168 // The name of the thread. Used for debugging purposes. | 183 // The name of the thread. Used for debugging purposes. |
| 169 std::string name_; | 184 std::string name_; |
| 170 | 185 |
| 171 friend class ThreadQuitTask; | 186 friend class ThreadQuitTask; |
| 172 | 187 |
| 173 DISALLOW_COPY_AND_ASSIGN(Thread); | 188 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 174 }; | 189 }; |
| 175 | 190 |
| 176 } // namespace base | 191 } // namespace base |
| 177 | 192 |
| 178 #endif // BASE_THREAD_H_ | 193 #endif // BASE_THREAD_H_ |
| OLD | NEW |