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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 Thread::ScopedDisallowBlockingCalls::ScopedDisallowBlockingCalls() | 131 Thread::ScopedDisallowBlockingCalls::ScopedDisallowBlockingCalls() |
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, bool init_queue) |
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 if (init_queue) { |
| 152 DoInit(); |
| 153 } |
151 } | 154 } |
152 | 155 |
153 Thread::~Thread() { | 156 Thread::~Thread() { |
154 Stop(); | 157 Stop(); |
155 Clear(NULL); | 158 DoDestroy(); |
156 } | 159 } |
157 | 160 |
158 bool Thread::SleepMs(int milliseconds) { | 161 bool Thread::SleepMs(int milliseconds) { |
159 AssertBlockingIsAllowedOnCurrentThread(); | 162 AssertBlockingIsAllowedOnCurrentThread(); |
160 | 163 |
161 #if defined(WEBRTC_WIN) | 164 #if defined(WEBRTC_WIN) |
162 ::Sleep(milliseconds); | 165 ::Sleep(milliseconds); |
163 return true; | 166 return true; |
164 #else | 167 #else |
165 // POSIX has both a usleep() and a nanosleep(), but the former is deprecated, | 168 // 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 Loading... |
531 if (SUCCEEDED(hr)) { | 534 if (SUCCEEDED(hr)) { |
532 Thread::Run(); | 535 Thread::Run(); |
533 CoUninitialize(); | 536 CoUninitialize(); |
534 } else { | 537 } else { |
535 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; | 538 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; |
536 } | 539 } |
537 } | 540 } |
538 #endif | 541 #endif |
539 | 542 |
540 } // namespace rtc | 543 } // namespace rtc |
OLD | NEW |