Chromium Code Reviews| 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 #include "base/threading/thread.h" | 5 #include "base/threading/thread.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 10 #include "base/threading/thread_id_name_manager.h" | 10 #include "base/threading/thread_id_name_manager.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 running_(false), | 59 running_(false), |
| 60 startup_data_(NULL), | 60 startup_data_(NULL), |
| 61 thread_(0), | 61 thread_(0), |
| 62 message_loop_(NULL), | 62 message_loop_(NULL), |
| 63 thread_id_(kInvalidThreadId), | 63 thread_id_(kInvalidThreadId), |
| 64 name_(name) { | 64 name_(name) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 Thread::~Thread() { | 67 Thread::~Thread() { |
| 68 Stop(); | 68 Stop(); |
| 69 ThreadIdNameManager::GetInstance()->RemoveName(thread_id_); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 bool Thread::Start() { | 71 bool Thread::Start() { |
| 73 Options options; | 72 Options options; |
| 74 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
| 75 if (com_status_ == STA) | 74 if (com_status_ == STA) |
| 76 options.message_loop_type = MessageLoop::TYPE_UI; | 75 options.message_loop_type = MessageLoop::TYPE_UI; |
| 77 #endif | 76 #endif |
| 78 return StartWithOptions(options); | 77 return StartWithOptions(options); |
| 79 } | 78 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 113 |
| 115 StopSoon(); | 114 StopSoon(); |
| 116 | 115 |
| 117 // Wait for the thread to exit. | 116 // Wait for the thread to exit. |
| 118 // | 117 // |
| 119 // TODO(darin): Unfortunately, we need to keep message_loop_ around until | 118 // TODO(darin): Unfortunately, we need to keep message_loop_ around until |
| 120 // the thread exits. Some consumers are abusing the API. Make them stop. | 119 // the thread exits. Some consumers are abusing the API. Make them stop. |
| 121 // | 120 // |
| 122 PlatformThread::Join(thread_); | 121 PlatformThread::Join(thread_); |
| 123 | 122 |
| 123 ThreadIdNameManager::GetInstance()->RemoveName(thread_id_); | |
|
jar (doing other things)
2013/05/14 16:49:10
Given the problem you had... this solution is stil
dsinclair
2013/05/14 17:00:17
You're right, there is still a race here.
Looking
jar (doing other things)
2013/05/14 19:55:06
I don't fully grok the use case... but I suspect y
| |
| 124 | |
| 124 // The thread should NULL message_loop_ on exit. | 125 // The thread should NULL message_loop_ on exit. |
| 125 DCHECK(!message_loop_); | 126 DCHECK(!message_loop_); |
| 126 | 127 |
| 127 // The thread no longer needs to be joined. | 128 // The thread no longer needs to be joined. |
| 128 started_ = false; | 129 started_ = false; |
| 129 | 130 |
| 130 stopping_ = false; | 131 stopping_ = false; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void Thread::StopSoon() { | 134 void Thread::StopSoon() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 207 |
| 207 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. | 208 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
| 208 DCHECK(GetThreadWasQuitProperly()); | 209 DCHECK(GetThreadWasQuitProperly()); |
| 209 | 210 |
| 210 // We can't receive messages anymore. | 211 // We can't receive messages anymore. |
| 211 message_loop_ = NULL; | 212 message_loop_ = NULL; |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // namespace base | 216 } // namespace base |
| OLD | NEW |