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" | 9 #include "base/profiler/scoped_tracker.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 bool Thread::Start() { | 88 bool Thread::Start() { |
89 Options options; | 89 Options options; |
90 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
91 if (com_status_ == STA) | 91 if (com_status_ == STA) |
92 options.message_loop_type = MessageLoop::TYPE_UI; | 92 options.message_loop_type = MessageLoop::TYPE_UI; |
93 #endif | 93 #endif |
94 return StartWithOptions(options); | 94 return StartWithOptions(options); |
95 } | 95 } |
96 | 96 |
97 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 | |
103 DCHECK(!message_loop_); | 98 DCHECK(!message_loop_); |
104 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
105 DCHECK((com_status_ != STA) || | 100 DCHECK((com_status_ != STA) || |
106 (options.message_loop_type == MessageLoop::TYPE_UI)); | 101 (options.message_loop_type == MessageLoop::TYPE_UI)); |
107 #endif | 102 #endif |
108 | 103 |
109 SetThreadWasQuitProperly(false); | 104 SetThreadWasQuitProperly(false); |
110 | 105 |
111 StartupData startup_data(options); | 106 StartupData startup_data(options); |
112 startup_data_ = &startup_data; | 107 startup_data_ = &startup_data; |
113 | 108 |
114 if (!PlatformThread::Create(options.stack_size, this, &thread_)) { | 109 if (!PlatformThread::Create(options.stack_size, this, &thread_)) { |
115 DLOG(ERROR) << "failed to create thread"; | 110 DLOG(ERROR) << "failed to create thread"; |
116 startup_data_ = NULL; | 111 startup_data_ = NULL; |
117 return false; | 112 return false; |
118 } | 113 } |
119 | 114 |
120 // TODO(eroman): Remove once crbug.com/465458 is solved. | 115 // TODO(kinuko): Remove once crbug.com/465458 is solved. |
121 tracked_objects::ScopedTracker tracking_profile_wait( | 116 tracked_objects::ScopedTracker tracking_profile_wait( |
122 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 117 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
123 "465458 base::Thread::StartWithOptions (Wait)")); | 118 "465458 base::Thread::StartWithOptions (Wait)")); |
124 | 119 |
125 // Wait for the thread to start and initialize message_loop_ | 120 // Wait for the thread to start and initialize message_loop_ |
126 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 121 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
127 startup_data.event.Wait(); | 122 startup_data.event.Wait(); |
128 | 123 |
129 // set it to NULL so we don't keep a pointer to some object on the stack. | 124 // set it to NULL so we don't keep a pointer to some object on the stack. |
130 startup_data_ = NULL; | 125 startup_data_ = NULL; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 243 |
249 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. | 244 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
250 DCHECK(GetThreadWasQuitProperly()); | 245 DCHECK(GetThreadWasQuitProperly()); |
251 | 246 |
252 // We can't receive messages anymore. | 247 // We can't receive messages anymore. |
253 message_loop_ = NULL; | 248 message_loop_ = NULL; |
254 } | 249 } |
255 } | 250 } |
256 | 251 |
257 } // namespace base | 252 } // namespace base |
OLD | NEW |