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/profiler/scoped_tracker.h" |
| 10 #include "base/synchronization/waitable_event.h" |
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
10 #include "base/threading/thread_id_name_manager.h" | 12 #include "base/threading/thread_id_name_manager.h" |
11 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
12 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
13 #include "base/synchronization/waitable_event.h" | |
14 | 15 |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
17 #endif | 18 #endif |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // We use this thread-local variable to record whether or not a thread exited | 24 // We use this thread-local variable to record whether or not a thread exited |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bool Thread::Start() { | 88 bool Thread::Start() { |
88 Options options; | 89 Options options; |
89 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
90 if (com_status_ == STA) | 91 if (com_status_ == STA) |
91 options.message_loop_type = MessageLoop::TYPE_UI; | 92 options.message_loop_type = MessageLoop::TYPE_UI; |
92 #endif | 93 #endif |
93 return StartWithOptions(options); | 94 return StartWithOptions(options); |
94 } | 95 } |
95 | 96 |
96 bool Thread::StartWithOptions(const Options& options) { | 97 bool Thread::StartWithOptions(const Options& options) { |
| 98 // TODO(eroman): Remove once crbug.com/465458 is solved. |
| 99 tracked_objects::ScopedTracker tracking_profile( |
| 100 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 101 "465458 base::Thread::StartWithOptions")); |
| 102 |
97 DCHECK(!message_loop_); | 103 DCHECK(!message_loop_); |
98 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
99 DCHECK((com_status_ != STA) || | 105 DCHECK((com_status_ != STA) || |
100 (options.message_loop_type == MessageLoop::TYPE_UI)); | 106 (options.message_loop_type == MessageLoop::TYPE_UI)); |
101 #endif | 107 #endif |
102 | 108 |
103 SetThreadWasQuitProperly(false); | 109 SetThreadWasQuitProperly(false); |
104 | 110 |
105 StartupData startup_data(options); | 111 StartupData startup_data(options); |
106 startup_data_ = &startup_data; | 112 startup_data_ = &startup_data; |
107 | 113 |
108 if (!PlatformThread::Create(options.stack_size, this, &thread_)) { | 114 if (!PlatformThread::Create(options.stack_size, this, &thread_)) { |
109 DLOG(ERROR) << "failed to create thread"; | 115 DLOG(ERROR) << "failed to create thread"; |
110 startup_data_ = NULL; | 116 startup_data_ = NULL; |
111 return false; | 117 return false; |
112 } | 118 } |
113 | 119 |
| 120 // TODO(eroman): Remove once crbug.com/465458 is solved. |
| 121 tracked_objects::ScopedTracker tracking_profile_wait( |
| 122 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 123 "465458 base::Thread::StartWithOptions (Wait)")); |
| 124 |
114 // Wait for the thread to start and initialize message_loop_ | 125 // Wait for the thread to start and initialize message_loop_ |
115 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 126 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
116 startup_data.event.Wait(); | 127 startup_data.event.Wait(); |
117 | 128 |
118 // set it to NULL so we don't keep a pointer to some object on the stack. | 129 // set it to NULL so we don't keep a pointer to some object on the stack. |
119 startup_data_ = NULL; | 130 startup_data_ = NULL; |
120 started_ = true; | 131 started_ = true; |
121 | 132 |
122 DCHECK(message_loop_); | 133 DCHECK(message_loop_); |
123 return true; | 134 return true; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 248 |
238 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. | 249 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
239 DCHECK(GetThreadWasQuitProperly()); | 250 DCHECK(GetThreadWasQuitProperly()); |
240 | 251 |
241 // We can't receive messages anymore. | 252 // We can't receive messages anymore. |
242 message_loop_ = NULL; | 253 message_loop_ = NULL; |
243 } | 254 } |
244 } | 255 } |
245 | 256 |
246 } // namespace base | 257 } // namespace base |
OLD | NEW |