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" | |
12 #include "base/memory/scoped_ptr.h" | |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
14 | 16 |
15 namespace base { | 17 namespace base { |
16 | 18 |
19 class MessagePump; | |
20 | |
17 // A simple thread abstraction that establishes a MessageLoop on a new thread. | 21 // A simple thread abstraction that establishes a MessageLoop on a new thread. |
18 // The consumer uses the MessageLoop of the thread to cause code to execute on | 22 // The consumer uses the MessageLoop of the thread to cause code to execute on |
19 // the thread. When this object is destroyed the thread is terminated. All | 23 // the thread. When this object is destroyed the thread is terminated. All |
20 // pending tasks queued on the thread's message loop will run to completion | 24 // pending tasks queued on the thread's message loop will run to completion |
21 // before the thread is terminated. | 25 // before the thread is terminated. |
22 // | 26 // |
23 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). | 27 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). |
24 // | 28 // |
25 // After the thread is stopped, the destruction sequence is: | 29 // After the thread is stopped, the destruction sequence is: |
26 // | 30 // |
27 // (1) Thread::CleanUp() | 31 // (1) Thread::CleanUp() |
28 // (2) MessageLoop::~MessageLoop | 32 // (2) MessageLoop::~MessageLoop |
29 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop | 33 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop |
30 class BASE_EXPORT Thread : PlatformThread::Delegate { | 34 class BASE_EXPORT Thread : PlatformThread::Delegate { |
31 public: | 35 public: |
32 struct Options { | 36 struct Options { |
33 Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} | 37 typedef Callback<scoped_ptr<MessagePump>()> MessagePumpFactory; |
38 | |
39 Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) { | |
40 } | |
34 Options(MessageLoop::Type type, size_t size) | 41 Options(MessageLoop::Type type, size_t size) |
35 : message_loop_type(type), stack_size(size) {} | 42 : message_loop_type(type), |
43 stack_size(size) {} | |
36 | 44 |
37 // Specifies the type of message loop that will be allocated on the thread. | 45 // Specifies the type of message loop that will be allocated on the thread. |
38 MessageLoop::Type message_loop_type; | 46 MessageLoop::Type message_loop_type; |
39 | 47 |
48 // Used to create the MessagePump for the MessageLoop. The callback is Run() | |
49 // on the thread. If message_pump_factory.is_null(), then a MessagePump | |
50 // appropriate for |message_loop_type| is created. | |
51 MessagePumpFactory message_pump_factory; | |
darin (slow to review)
2013/11/07 21:03:38
You might mention that message_pump_factory overri
| |
52 | |
40 // Specifies the maximum stack size that the thread is allowed to use. | 53 // Specifies the maximum stack size that the thread is allowed to use. |
41 // This does not necessarily correspond to the thread's initial stack size. | 54 // This does not necessarily correspond to the thread's initial stack size. |
42 // A value of 0 indicates that the default maximum should be used. | 55 // A value of 0 indicates that the default maximum should be used. |
43 size_t stack_size; | 56 size_t stack_size; |
44 }; | 57 }; |
45 | 58 |
46 // Constructor. | 59 // Constructor. |
47 // name is a display string to identify the thread. | 60 // name is a display string to identify the thread. |
48 explicit Thread(const char* name); | 61 explicit Thread(const char* name); |
49 | 62 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 std::string name_; | 220 std::string name_; |
208 | 221 |
209 friend void ThreadQuitHelper(); | 222 friend void ThreadQuitHelper(); |
210 | 223 |
211 DISALLOW_COPY_AND_ASSIGN(Thread); | 224 DISALLOW_COPY_AND_ASSIGN(Thread); |
212 }; | 225 }; |
213 | 226 |
214 } // namespace base | 227 } // namespace base |
215 | 228 |
216 #endif // BASE_THREADING_THREAD_H_ | 229 #endif // BASE_THREADING_THREAD_H_ |
OLD | NEW |