| 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 #include "base/thread.h" | 5 #include "base/thread.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 9 #include "base/thread_local.h" | 9 #include "base/thread_local.h" |
| 10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // with ThreadMain, so we annotate it to stay silent under ThreadSanitizer. | 129 // with ThreadMain, so we annotate it to stay silent under ThreadSanitizer. |
| 130 DCHECK_NE(ANNOTATE_UNPROTECTED_READ(thread_id_), PlatformThread::CurrentId()); | 130 DCHECK_NE(ANNOTATE_UNPROTECTED_READ(thread_id_), PlatformThread::CurrentId()); |
| 131 | 131 |
| 132 if (stopping_ || !message_loop_) | 132 if (stopping_ || !message_loop_) |
| 133 return; | 133 return; |
| 134 | 134 |
| 135 stopping_ = true; | 135 stopping_ = true; |
| 136 message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); | 136 message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 #if defined(OS_WIN) |
| 140 #pragma warning (disable: 4748) |
| 141 #pragma optimize( "", off ) |
| 142 #endif |
| 143 |
| 139 void Thread::Run(MessageLoop* message_loop) { | 144 void Thread::Run(MessageLoop* message_loop) { |
| 145 #if defined(OS_WIN) |
| 146 // Logging the thread name for debugging. |
| 147 // TODO(huanr): remove after done. |
| 148 // http://code.google.com/p/chromium/issues/detail?id=54307 |
| 149 char name[16]; |
| 150 strncpy(name, name_.c_str(), arraysize(name) - 1); |
| 151 name[arraysize(name) - 1] = '\0'; |
| 152 #endif |
| 140 message_loop->Run(); | 153 message_loop->Run(); |
| 141 } | 154 } |
| 142 | 155 |
| 156 #if defined(OS_WIN) |
| 157 #pragma optimize( "", on ) |
| 158 #pragma warning (default: 4748) |
| 159 #endif |
| 160 |
| 143 void Thread::ThreadMain() { | 161 void Thread::ThreadMain() { |
| 144 { | 162 { |
| 145 // The message loop for this thread. | 163 // The message loop for this thread. |
| 146 MessageLoop message_loop(startup_data_->options.message_loop_type); | 164 MessageLoop message_loop(startup_data_->options.message_loop_type); |
| 147 | 165 |
| 148 // Complete the initialization of our Thread object. | 166 // Complete the initialization of our Thread object. |
| 149 thread_id_ = PlatformThread::CurrentId(); | 167 thread_id_ = PlatformThread::CurrentId(); |
| 150 PlatformThread::SetName(name_.c_str()); | 168 PlatformThread::SetName(name_.c_str()); |
| 151 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. | 169 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. |
| 152 message_loop.set_thread_name(name_); | 170 message_loop.set_thread_name(name_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 171 | 189 |
| 172 // We can't receive messages anymore. | 190 // We can't receive messages anymore. |
| 173 message_loop_ = NULL; | 191 message_loop_ = NULL; |
| 174 message_loop_proxy_ = NULL; | 192 message_loop_proxy_ = NULL; |
| 175 } | 193 } |
| 176 CleanUpAfterMessageLoopDestruction(); | 194 CleanUpAfterMessageLoopDestruction(); |
| 177 thread_id_ = 0; | 195 thread_id_ = 0; |
| 178 } | 196 } |
| 179 | 197 |
| 180 } // namespace base | 198 } // namespace base |
| OLD | NEW |