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

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

Issue 2023193002: Protect MessageQueue stop field with a critical section to avoid data races. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 212 }
213 return true; 213 return true;
214 } 214 }
215 215
216 bool Thread::Start(Runnable* runnable) { 216 bool Thread::Start(Runnable* runnable) {
217 ASSERT(owned_); 217 ASSERT(owned_);
218 if (!owned_) return false; 218 if (!owned_) return false;
219 ASSERT(!running()); 219 ASSERT(!running());
220 if (running()) return false; 220 if (running()) return false;
221 221
222 Restart(); // reset fStop_ if the thread is being restarted 222 Restart(); // reset IsQuitting() if the thread is being restarted
223 223
224 // Make sure that ThreadManager is created on the main thread before 224 // Make sure that ThreadManager is created on the main thread before
225 // we start a new thread. 225 // we start a new thread.
226 ThreadManager::Instance(); 226 ThreadManager::Instance();
227 227
228 ThreadInit* init = new ThreadInit; 228 ThreadInit* init = new ThreadInit;
229 init->thread = this; 229 init->thread = this;
230 init->runnable = runnable; 230 init->runnable = runnable;
231 #if defined(WEBRTC_WIN) 231 #if defined(WEBRTC_WIN)
232 thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PreRun, init, 0, 232 thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PreRun, init, 0,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 bool Thread::IsOwned() { 337 bool Thread::IsOwned() {
338 return owned_; 338 return owned_;
339 } 339 }
340 340
341 void Thread::Stop() { 341 void Thread::Stop() {
342 MessageQueue::Quit(); 342 MessageQueue::Quit();
343 Join(); 343 Join();
344 } 344 }
345 345
346 void Thread::Send(MessageHandler* phandler, uint32_t id, MessageData* pdata) { 346 void Thread::Send(MessageHandler* phandler, uint32_t id, MessageData* pdata) {
347 if (fStop_) 347 if (IsQuitting())
348 return; 348 return;
349 349
350 // Sent messages are sent to the MessageHandler directly, in the context 350 // Sent messages are sent to the MessageHandler directly, in the context
351 // of "thread", like Win32 SendMessage. If in the right context, 351 // of "thread", like Win32 SendMessage. If in the right context,
352 // call the handler directly. 352 // call the handler directly.
353 Message msg; 353 Message msg;
354 msg.phandler = phandler; 354 msg.phandler = phandler;
355 msg.message_id = id; 355 msg.message_id = id;
356 msg.pdata = pdata; 356 msg.pdata = pdata;
357 if (IsCurrent()) { 357 if (IsCurrent()) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 if (SUCCEEDED(hr)) { 556 if (SUCCEEDED(hr)) {
557 Thread::Run(); 557 Thread::Run();
558 CoUninitialize(); 558 CoUninitialize();
559 } else { 559 } else {
560 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; 560 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr;
561 } 561 }
562 } 562 }
563 #endif 563 #endif
564 564
565 } // namespace rtc 565 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698