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

Side by Side Diff: webrtc/base/thread.cc

Issue 1666863002: Fix race between Thread ctor/dtor and MessageQueueManager registrations. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
« webrtc/base/messagequeue.cc ('K') | « webrtc/base/messagequeue.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 : thread_(Thread::Current()), 132 : thread_(Thread::Current()),
133 previous_state_(thread_->SetAllowBlockingCalls(false)) { 133 previous_state_(thread_->SetAllowBlockingCalls(false)) {
134 } 134 }
135 135
136 Thread::ScopedDisallowBlockingCalls::~ScopedDisallowBlockingCalls() { 136 Thread::ScopedDisallowBlockingCalls::~ScopedDisallowBlockingCalls() {
137 ASSERT(thread_->IsCurrent()); 137 ASSERT(thread_->IsCurrent());
138 thread_->SetAllowBlockingCalls(previous_state_); 138 thread_->SetAllowBlockingCalls(previous_state_);
139 } 139 }
140 140
141 Thread::Thread(SocketServer* ss) 141 Thread::Thread(SocketServer* ss)
142 : MessageQueue(ss), 142 : MessageQueue(ss, false),
143 running_(true, false), 143 running_(true, false),
144 #if defined(WEBRTC_WIN) 144 #if defined(WEBRTC_WIN)
145 thread_(NULL), 145 thread_(NULL),
146 thread_id_(0), 146 thread_id_(0),
147 #endif 147 #endif
148 owned_(true), 148 owned_(true),
149 blocking_calls_allowed_(true) { 149 blocking_calls_allowed_(true) {
150 SetName("Thread", this); // default name 150 SetName("Thread", this); // default name
151 MessageQueueManager::Add(this);
pthatcher1 2016/02/03 23:51:47 So, is this basically to make sure that SocketServ
joachim 2016/02/04 00:01:20 Please see my comment in messagequeue.cc. The chan
151 } 152 }
152 153
153 Thread::~Thread() { 154 Thread::~Thread() {
154 Stop(); 155 Stop();
155 Clear(NULL); 156 DoDestroy();
pthatcher1 2016/02/03 23:51:47 Why do we want to not call Clear(NULL) here? Is i
joachim 2016/02/04 00:01:20 We want to have the object removed from the Messag
pthatcher1 2016/02/04 00:50:38 That makes it clear why we should call DoDestroy()
joachim 2016/02/04 01:00:09 DoDestroy calls Clear(NULL) internally so I think
pthatcher1 2016/02/03 23:51:47 Can you leave a comment like "We can't rely on the
joachim 2016/02/04 00:01:20 I added a similar comment at the destructor of Mes
pthatcher1 2016/02/04 00:50:38 FYI, I don't see the new comments.
joachim 2016/02/04 01:00:09 Sorry for not being clearer, it's in messagequeue.
pthatcher1 2016/02/04 03:14:11 Right, but can you put one in the ctor also explai
joachim 2016/02/04 08:35:56 Done.
156 } 157 }
157 158
158 bool Thread::SleepMs(int milliseconds) { 159 bool Thread::SleepMs(int milliseconds) {
159 AssertBlockingIsAllowedOnCurrentThread(); 160 AssertBlockingIsAllowedOnCurrentThread();
160 161
161 #if defined(WEBRTC_WIN) 162 #if defined(WEBRTC_WIN)
162 ::Sleep(milliseconds); 163 ::Sleep(milliseconds);
163 return true; 164 return true;
164 #else 165 #else
165 // POSIX has both a usleep() and a nanosleep(), but the former is deprecated, 166 // POSIX has both a usleep() and a nanosleep(), but the former is deprecated,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 if (SUCCEEDED(hr)) { 532 if (SUCCEEDED(hr)) {
532 Thread::Run(); 533 Thread::Run();
533 CoUninitialize(); 534 CoUninitialize();
534 } else { 535 } else {
535 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; 536 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr;
536 } 537 }
537 } 538 }
538 #endif 539 #endif
539 540
540 } // namespace rtc 541 } // namespace rtc
OLDNEW
« webrtc/base/messagequeue.cc ('K') | « webrtc/base/messagequeue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698