| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 22 // | 22 // |
| 23 // After the thread is stopped, the destruction sequence is: | 23 // After the thread is stopped, the destruction sequence is: |
| 24 // | 24 // |
| 25 // (1) Thread::CleanUp() | 25 // (1) Thread::CleanUp() |
| 26 // (2) MessageLoop::~MessageLoop | 26 // (2) MessageLoop::~MessageLoop |
| 27 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop | 27 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop |
| 28 // (4) Thread::CleanUpAfterMessageLoopDestruction() | 28 // (4) Thread::CleanUpAfterMessageLoopDestruction() |
| 29 class Thread : PlatformThread::Delegate { | 29 class Thread : PlatformThread::Delegate { |
| 30 public: | 30 public: |
| 31 struct Options { | 31 struct Options { |
| 32 Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} |
| 33 Options(MessageLoop::Type type, size_t size) |
| 34 : message_loop_type(type), stack_size(size) {} |
| 35 |
| 32 // Specifies the type of message loop that will be allocated on the thread. | 36 // Specifies the type of message loop that will be allocated on the thread. |
| 33 MessageLoop::Type message_loop_type; | 37 MessageLoop::Type message_loop_type; |
| 34 | 38 |
| 35 // Specifies the maximum stack size that the thread is allowed to use. | 39 // Specifies the maximum stack size that the thread is allowed to use. |
| 36 // This does not necessarily correspond to the thread's initial stack size. | 40 // This does not necessarily correspond to the thread's initial stack size. |
| 37 // A value of 0 indicates that the default maximum should be used. | 41 // A value of 0 indicates that the default maximum should be used. |
| 38 size_t stack_size; | 42 size_t stack_size; |
| 39 | |
| 40 Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} | |
| 41 Options(MessageLoop::Type type, size_t size) | |
| 42 : message_loop_type(type), stack_size(size) {} | |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // Constructor. | 45 // Constructor. |
| 46 // name is a display string to identify the thread. | 46 // name is a display string to identify the thread. |
| 47 explicit Thread(const char* name); | 47 explicit Thread(const char* name); |
| 48 | 48 |
| 49 // Destroys the thread, stopping it if necessary. | 49 // Destroys the thread, stopping it if necessary. |
| 50 // | 50 // |
| 51 // NOTE: If you are subclassing from Thread, and you wish for your CleanUp | 51 // NOTE: If you are subclassing from Thread, and you wish for your CleanUp |
| 52 // method to be called, then you need to call Stop() from your destructor. | 52 // method to be called, then you need to call Stop() from your destructor. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 virtual void CleanUpAfterMessageLoopDestruction() {} | 145 virtual void CleanUpAfterMessageLoopDestruction() {} |
| 146 | 146 |
| 147 static void SetThreadWasQuitProperly(bool flag); | 147 static void SetThreadWasQuitProperly(bool flag); |
| 148 static bool GetThreadWasQuitProperly(); | 148 static bool GetThreadWasQuitProperly(); |
| 149 | 149 |
| 150 void set_message_loop(MessageLoop* message_loop) { | 150 void set_message_loop(MessageLoop* message_loop) { |
| 151 message_loop_ = message_loop; | 151 message_loop_ = message_loop; |
| 152 } | 152 } |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 bool thread_was_started() const { return started_; } |
| 156 |
| 155 // PlatformThread::Delegate methods: | 157 // PlatformThread::Delegate methods: |
| 156 virtual void ThreadMain(); | 158 virtual void ThreadMain(); |
| 157 | 159 |
| 158 bool thread_was_started() const { return started_; } | |
| 159 | |
| 160 // Whether we successfully started the thread. | 160 // Whether we successfully started the thread. |
| 161 bool started_; | 161 bool started_; |
| 162 | 162 |
| 163 // If true, we're in the middle of stopping, and shouldn't access | 163 // If true, we're in the middle of stopping, and shouldn't access |
| 164 // |message_loop_|. It may non-NULL and invalid. | 164 // |message_loop_|. It may non-NULL and invalid. |
| 165 bool stopping_; | 165 bool stopping_; |
| 166 | 166 |
| 167 // Used to pass data to ThreadMain. | 167 // Used to pass data to ThreadMain. |
| 168 struct StartupData; | 168 struct StartupData; |
| 169 StartupData* startup_data_; | 169 StartupData* startup_data_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 186 std::string name_; | 186 std::string name_; |
| 187 | 187 |
| 188 friend class ThreadQuitTask; | 188 friend class ThreadQuitTask; |
| 189 | 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(Thread); | 190 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 } // namespace base | 193 } // namespace base |
| 194 | 194 |
| 195 #endif // BASE_THREAD_H_ | 195 #endif // BASE_THREAD_H_ |
| OLD | NEW |