OLD | NEW |
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 Loading... |
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); |
151 } | 152 } |
152 | 153 |
153 Thread::~Thread() { | 154 Thread::~Thread() { |
154 Stop(); | 155 Stop(); |
155 Clear(NULL); | 156 DoDestroy(); |
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } | 513 } |
513 | 514 |
514 AutoThread::AutoThread(SocketServer* ss) : Thread(ss) { | 515 AutoThread::AutoThread(SocketServer* ss) : Thread(ss) { |
515 if (!ThreadManager::Instance()->CurrentThread()) { | 516 if (!ThreadManager::Instance()->CurrentThread()) { |
516 ThreadManager::Instance()->SetCurrentThread(this); | 517 ThreadManager::Instance()->SetCurrentThread(this); |
517 } | 518 } |
518 } | 519 } |
519 | 520 |
520 AutoThread::~AutoThread() { | 521 AutoThread::~AutoThread() { |
521 Stop(); | 522 Stop(); |
| 523 DoDestroy(); |
522 if (ThreadManager::Instance()->CurrentThread() == this) { | 524 if (ThreadManager::Instance()->CurrentThread() == this) { |
523 ThreadManager::Instance()->SetCurrentThread(NULL); | 525 ThreadManager::Instance()->SetCurrentThread(NULL); |
524 } | 526 } |
525 } | 527 } |
526 | 528 |
527 #if defined(WEBRTC_WIN) | 529 #if defined(WEBRTC_WIN) |
| 530 ComThread::~ComThread() { |
| 531 Stop(); |
| 532 DoDestroy(); |
| 533 } |
| 534 |
528 void ComThread::Run() { | 535 void ComThread::Run() { |
529 HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); | 536 HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); |
530 ASSERT(SUCCEEDED(hr)); | 537 ASSERT(SUCCEEDED(hr)); |
531 if (SUCCEEDED(hr)) { | 538 if (SUCCEEDED(hr)) { |
532 Thread::Run(); | 539 Thread::Run(); |
533 CoUninitialize(); | 540 CoUninitialize(); |
534 } else { | 541 } else { |
535 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; | 542 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; |
536 } | 543 } |
537 } | 544 } |
538 #endif | 545 #endif |
539 | 546 |
540 } // namespace rtc | 547 } // namespace rtc |
OLD | NEW |