Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: base/message_loop/message_loop.cc

Issue 1559353002: base: Fix DCHECK when thread creation fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tls resetting, add test. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 : MessageLoop(type, MessagePumpFactoryCallback()) { 126 : MessageLoop(type, MessagePumpFactoryCallback()) {
127 BindToCurrentThread(); 127 BindToCurrentThread();
128 } 128 }
129 129
130 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) 130 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
131 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) { 131 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) {
132 BindToCurrentThread(); 132 BindToCurrentThread();
133 } 133 }
134 134
135 MessageLoop::~MessageLoop() { 135 MessageLoop::~MessageLoop() {
136 // current() could be NULL if this message loop is destructed before it is 136 // If |pump_| is non-null, this message loop should be the current one on this
137 // bound to a thread. 137 // thread. Otherwise, this loop is being destructed before it was bound to a
138 DCHECK(current() == this || !current()); 138 // thread, so a different message loop (or no loop at all) may be current.
139 DCHECK((pump_ && current() == this) || current() != this);
danakj 2016/01/06 21:03:22 This would still pass if pump_ && current() != thi
Sami 2016/01/07 10:46:10 Ah, right you are. Fixed, thanks.
139 140
140 // iOS just attaches to the loop, it doesn't Run it. 141 // iOS just attaches to the loop, it doesn't Run it.
141 // TODO(stuartmorgan): Consider wiring up a Detach(). 142 // TODO(stuartmorgan): Consider wiring up a Detach().
142 #if !defined(OS_IOS) 143 #if !defined(OS_IOS)
143 DCHECK(!run_loop_); 144 DCHECK(!run_loop_);
144 #endif 145 #endif
145 146
146 #if defined(OS_WIN) 147 #if defined(OS_WIN)
147 if (in_high_res_mode_) 148 if (in_high_res_mode_)
148 Time::ActivateHighResolutionTimer(false); 149 Time::ActivateHighResolutionTimer(false);
(...skipping 21 matching lines...) Expand all
170 171
171 thread_task_runner_handle_.reset(); 172 thread_task_runner_handle_.reset();
172 173
173 // Tell the incoming queue that we are dying. 174 // Tell the incoming queue that we are dying.
174 incoming_task_queue_->WillDestroyCurrentMessageLoop(); 175 incoming_task_queue_->WillDestroyCurrentMessageLoop();
175 incoming_task_queue_ = NULL; 176 incoming_task_queue_ = NULL;
176 unbound_task_runner_ = NULL; 177 unbound_task_runner_ = NULL;
177 task_runner_ = NULL; 178 task_runner_ = NULL;
178 179
179 // OK, now make it so that no one can find us. 180 // OK, now make it so that no one can find us.
180 lazy_tls_ptr.Pointer()->Set(NULL); 181 if (current() == this)
danakj 2016/01/06 21:03:22 Yay for tests :o
Sami 2016/01/07 10:46:10 They're the best.
182 lazy_tls_ptr.Pointer()->Set(nullptr);
181 } 183 }
182 184
183 // static 185 // static
184 MessageLoop* MessageLoop::current() { 186 MessageLoop* MessageLoop::current() {
185 // TODO(darin): sadly, we cannot enable this yet since people call us even 187 // TODO(darin): sadly, we cannot enable this yet since people call us even
186 // when they have no intention of using us. 188 // when they have no intention of using us.
187 // DCHECK(loop) << "Ouch, did you forget to initialize me?"; 189 // DCHECK(loop) << "Ouch, did you forget to initialize me?";
188 return lazy_tls_ptr.Pointer()->Get(); 190 return lazy_tls_ptr.Pointer()->Get();
189 } 191 }
190 192
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 persistent, 756 persistent,
755 mode, 757 mode,
756 controller, 758 controller,
757 delegate); 759 delegate);
758 } 760 }
759 #endif 761 #endif
760 762
761 #endif // !defined(OS_NACL_SFI) 763 #endif // !defined(OS_NACL_SFI)
762 764
763 } // namespace base 765 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698