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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
15 #include "base/threading/thread_id_name_manager.h" | 15 #include "base/threading/thread_id_name_manager.h" |
16 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 | 19 |
20 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) | |
21 #include "base/files/file_descriptor_watcher_posix.h" | |
22 #endif | |
23 | |
20 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
21 #include "base/win/scoped_com_initializer.h" | 25 #include "base/win/scoped_com_initializer.h" |
22 #endif | 26 #endif |
23 | 27 |
24 namespace base { | 28 namespace base { |
25 | 29 |
26 namespace { | 30 namespace { |
27 | 31 |
28 // We use this thread-local variable to record whether or not a thread exited | 32 // We use this thread-local variable to record whether or not a thread exited |
29 // because its Stop method was called. This allows us to catch cases where | 33 // because its Stop method was called. This allows us to catch cases where |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Complete the initialization of our Thread object. | 292 // Complete the initialization of our Thread object. |
289 PlatformThread::SetName(name_.c_str()); | 293 PlatformThread::SetName(name_.c_str()); |
290 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. | 294 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. |
291 | 295 |
292 // Lazily initialize the |message_loop| so that it can run on this thread. | 296 // Lazily initialize the |message_loop| so that it can run on this thread. |
293 DCHECK(message_loop_); | 297 DCHECK(message_loop_); |
294 std::unique_ptr<MessageLoop> message_loop(message_loop_); | 298 std::unique_ptr<MessageLoop> message_loop(message_loop_); |
295 message_loop_->BindToCurrentThread(); | 299 message_loop_->BindToCurrentThread(); |
296 message_loop_->SetTimerSlack(message_loop_timer_slack_); | 300 message_loop_->SetTimerSlack(message_loop_timer_slack_); |
297 | 301 |
302 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) | |
303 // Allow threads running a MessageLoopForIO to use FileDescriptorWatcher API. | |
304 std::unique_ptr<FileDescriptorWatcher> file_descriptor_watcher; | |
305 if (MessageLoopForIO::IsCurrent()) { | |
306 file_descriptor_watcher.reset( | |
307 new FileDescriptorWatcher(MessageLoopForIO::current())); | |
dcheng
2016/09/26 17:34:40
Is there a time when this wouldn't return the same
fdoray
2016/09/26 17:44:07
No.
message_loop_->BindToCurrentThread() above se
| |
308 } | |
309 #endif | |
310 | |
298 #if defined(OS_WIN) | 311 #if defined(OS_WIN) |
299 std::unique_ptr<win::ScopedCOMInitializer> com_initializer; | 312 std::unique_ptr<win::ScopedCOMInitializer> com_initializer; |
300 if (com_status_ != NONE) { | 313 if (com_status_ != NONE) { |
301 com_initializer.reset((com_status_ == STA) ? | 314 com_initializer.reset((com_status_ == STA) ? |
302 new win::ScopedCOMInitializer() : | 315 new win::ScopedCOMInitializer() : |
303 new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA)); | 316 new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA)); |
304 } | 317 } |
305 #endif | 318 #endif |
306 | 319 |
307 // Let the thread do extra initialization. | 320 // Let the thread do extra initialization. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 run_loop_ = nullptr; | 356 run_loop_ = nullptr; |
344 } | 357 } |
345 | 358 |
346 void Thread::ThreadQuitHelper() { | 359 void Thread::ThreadQuitHelper() { |
347 DCHECK(run_loop_); | 360 DCHECK(run_loop_); |
348 run_loop_->QuitWhenIdle(); | 361 run_loop_->QuitWhenIdle(); |
349 SetThreadWasQuitProperly(true); | 362 SetThreadWasQuitProperly(true); |
350 } | 363 } |
351 | 364 |
352 } // namespace base | 365 } // namespace base |
OLD | NEW |