blob: 48a914451d75fd4e7de3ecea107a3cab6d9bbbcd [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/base/thread.h"
12
13#ifndef __has_feature
14#define __has_feature(x) 0 // Compatibility with non-clang or LLVM compilers.
15#endif // __has_feature
16
17#if defined(WEBRTC_WIN)
18#include <comdef.h>
19#elif defined(WEBRTC_POSIX)
20#include <time.h>
21#endif
22
23#include "webrtc/base/common.h"
24#include "webrtc/base/logging.h"
Tommiea14f0a2015-05-18 11:51:0625#include "webrtc/base/platform_thread.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2626#include "webrtc/base/stringutils.h"
27#include "webrtc/base/timeutils.h"
28
29#if !__has_feature(objc_arc) && (defined(WEBRTC_MAC))
30#include "webrtc/base/maccocoathreadhelper.h"
31#include "webrtc/base/scoped_autorelease_pool.h"
32#endif
33
tommi@webrtc.org7c64ed22015-03-17 14:25:3734#include "webrtc/base/trace_event.h"
35
henrike@webrtc.orgf0488722014-05-13 18:00:2636namespace rtc {
37
38ThreadManager* ThreadManager::Instance() {
Andrew MacDonald469c2c02015-05-23 00:50:2639 RTC_DEFINE_STATIC_LOCAL(ThreadManager, thread_manager, ());
henrike@webrtc.orgf0488722014-05-13 18:00:2640 return &thread_manager;
41}
42
43// static
44Thread* Thread::Current() {
45 return ThreadManager::Instance()->CurrentThread();
46}
47
48#if defined(WEBRTC_POSIX)
49ThreadManager::ThreadManager() {
50 pthread_key_create(&key_, NULL);
51#ifndef NO_MAIN_THREAD_WRAPPING
52 WrapCurrentThread();
53#endif
54#if !__has_feature(objc_arc) && (defined(WEBRTC_MAC))
55 // Under Automatic Reference Counting (ARC), you cannot use autorelease pools
56 // directly. Instead, you use @autoreleasepool blocks instead. Also, we are
57 // maintaining thread safety using immutability within context of GCD dispatch
58 // queues in this case.
59 InitCocoaMultiThreading();
60#endif
61}
62
63ThreadManager::~ThreadManager() {
64#if __has_feature(objc_arc)
65 @autoreleasepool
66#elif defined(WEBRTC_MAC)
67 // This is called during exit, at which point apparently no NSAutoreleasePools
68 // are available; but we might still need them to do cleanup (or we get the
69 // "no autoreleasepool in place, just leaking" warning when exiting).
70 ScopedAutoreleasePool pool;
71#endif
72 {
73 UnwrapCurrentThread();
74 pthread_key_delete(key_);
75 }
76}
77
78Thread *ThreadManager::CurrentThread() {
79 return static_cast<Thread *>(pthread_getspecific(key_));
80}
81
82void ThreadManager::SetCurrentThread(Thread *thread) {
83 pthread_setspecific(key_, thread);
84}
85#endif
86
87#if defined(WEBRTC_WIN)
88ThreadManager::ThreadManager() {
89 key_ = TlsAlloc();
90#ifndef NO_MAIN_THREAD_WRAPPING
91 WrapCurrentThread();
92#endif
93}
94
95ThreadManager::~ThreadManager() {
96 UnwrapCurrentThread();
97 TlsFree(key_);
98}
99
100Thread *ThreadManager::CurrentThread() {
101 return static_cast<Thread *>(TlsGetValue(key_));
102}
103
104void ThreadManager::SetCurrentThread(Thread *thread) {
105 TlsSetValue(key_, thread);
106}
107#endif
108
109Thread *ThreadManager::WrapCurrentThread() {
110 Thread* result = CurrentThread();
111 if (NULL == result) {
112 result = new Thread();
jiayl@webrtc.orgba737cb2014-09-18 16:45:21113 result->WrapCurrentWithThreadManager(this, true);
henrike@webrtc.orgf0488722014-05-13 18:00:26114 }
115 return result;
116}
117
118void ThreadManager::UnwrapCurrentThread() {
119 Thread* t = CurrentThread();
120 if (t && !(t->IsOwned())) {
121 t->UnwrapCurrent();
122 delete t;
123 }
124}
125
126struct ThreadInit {
127 Thread* thread;
128 Runnable* runnable;
129};
130
henrike@webrtc.org92a9bac2014-07-14 22:03:57131Thread::ScopedDisallowBlockingCalls::ScopedDisallowBlockingCalls()
132 : thread_(Thread::Current()),
133 previous_state_(thread_->SetAllowBlockingCalls(false)) {
134}
135
136Thread::ScopedDisallowBlockingCalls::~ScopedDisallowBlockingCalls() {
137 ASSERT(thread_->IsCurrent());
138 thread_->SetAllowBlockingCalls(previous_state_);
139}
140
henrike@webrtc.orgf0488722014-05-13 18:00:26141Thread::Thread(SocketServer* ss)
142 : MessageQueue(ss),
143 priority_(PRIORITY_NORMAL),
fischman@webrtc.orge5063b12014-05-23 17:28:50144 running_(true, false),
henrike@webrtc.orgf0488722014-05-13 18:00:26145#if defined(WEBRTC_WIN)
146 thread_(NULL),
147 thread_id_(0),
148#endif
henrike@webrtc.org92a9bac2014-07-14 22:03:57149 owned_(true),
150 blocking_calls_allowed_(true) {
henrike@webrtc.orgf0488722014-05-13 18:00:26151 SetName("Thread", this); // default name
152}
153
154Thread::~Thread() {
155 Stop();
henrike@webrtc.org99b41622014-05-21 20:42:17156 Clear(NULL);
henrike@webrtc.orgf0488722014-05-13 18:00:26157}
158
159bool Thread::SleepMs(int milliseconds) {
henrike@webrtc.org92a9bac2014-07-14 22:03:57160 AssertBlockingIsAllowedOnCurrentThread();
161
henrike@webrtc.orgf0488722014-05-13 18:00:26162#if defined(WEBRTC_WIN)
163 ::Sleep(milliseconds);
164 return true;
165#else
166 // POSIX has both a usleep() and a nanosleep(), but the former is deprecated,
167 // so we use nanosleep() even though it has greater precision than necessary.
168 struct timespec ts;
169 ts.tv_sec = milliseconds / 1000;
170 ts.tv_nsec = (milliseconds % 1000) * 1000000;
171 int ret = nanosleep(&ts, NULL);
172 if (ret != 0) {
173 LOG_ERR(LS_WARNING) << "nanosleep() returning early";
174 return false;
175 }
176 return true;
177#endif
178}
179
180bool Thread::SetName(const std::string& name, const void* obj) {
fischman@webrtc.orge5063b12014-05-23 17:28:50181 if (running()) return false;
henrike@webrtc.orgf0488722014-05-13 18:00:26182 name_ = name;
183 if (obj) {
184 char buf[16];
185 sprintfn(buf, sizeof(buf), " 0x%p", obj);
186 name_ += buf;
187 }
188 return true;
189}
190
191bool Thread::SetPriority(ThreadPriority priority) {
192#if defined(WEBRTC_WIN)
fischman@webrtc.orge5063b12014-05-23 17:28:50193 if (running()) {
jiayl@webrtc.orgba737cb2014-09-18 16:45:21194 ASSERT(thread_ != NULL);
henrike@webrtc.orgf0488722014-05-13 18:00:26195 BOOL ret = FALSE;
196 if (priority == PRIORITY_NORMAL) {
197 ret = ::SetThreadPriority(thread_, THREAD_PRIORITY_NORMAL);
198 } else if (priority == PRIORITY_HIGH) {
199 ret = ::SetThreadPriority(thread_, THREAD_PRIORITY_HIGHEST);
200 } else if (priority == PRIORITY_ABOVE_NORMAL) {
201 ret = ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL);
202 } else if (priority == PRIORITY_IDLE) {
203 ret = ::SetThreadPriority(thread_, THREAD_PRIORITY_IDLE);
204 }
205 if (!ret) {
206 return false;
207 }
208 }
209 priority_ = priority;
210 return true;
211#else
212 // TODO: Implement for Linux/Mac if possible.
fischman@webrtc.orge5063b12014-05-23 17:28:50213 if (running()) return false;
henrike@webrtc.orgf0488722014-05-13 18:00:26214 priority_ = priority;
215 return true;
216#endif
217}
218
219bool Thread::Start(Runnable* runnable) {
220 ASSERT(owned_);
221 if (!owned_) return false;
fischman@webrtc.orge5063b12014-05-23 17:28:50222 ASSERT(!running());
223 if (running()) return false;
henrike@webrtc.orgf0488722014-05-13 18:00:26224
225 Restart(); // reset fStop_ if the thread is being restarted
226
227 // Make sure that ThreadManager is created on the main thread before
228 // we start a new thread.
229 ThreadManager::Instance();
230
231 ThreadInit* init = new ThreadInit;
232 init->thread = this;
233 init->runnable = runnable;
234#if defined(WEBRTC_WIN)
235 DWORD flags = 0;
236 if (priority_ != PRIORITY_NORMAL) {
237 flags = CREATE_SUSPENDED;
238 }
239 thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PreRun, init, flags,
240 &thread_id_);
241 if (thread_) {
fischman@webrtc.orge5063b12014-05-23 17:28:50242 running_.Set();
henrike@webrtc.orgf0488722014-05-13 18:00:26243 if (priority_ != PRIORITY_NORMAL) {
244 SetPriority(priority_);
245 ::ResumeThread(thread_);
246 }
247 } else {
248 return false;
249 }
250#elif defined(WEBRTC_POSIX)
251 pthread_attr_t attr;
252 pthread_attr_init(&attr);
253
254 // Thread priorities are not supported in NaCl.
255#if !defined(__native_client__)
256 if (priority_ != PRIORITY_NORMAL) {
257 if (priority_ == PRIORITY_IDLE) {
258 // There is no POSIX-standard way to set a below-normal priority for an
259 // individual thread (only whole process), so let's not support it.
260 LOG(LS_WARNING) << "PRIORITY_IDLE not supported";
261 } else {
262 // Set real-time round-robin policy.
263 if (pthread_attr_setschedpolicy(&attr, SCHED_RR) != 0) {
264 LOG(LS_ERROR) << "pthread_attr_setschedpolicy";
265 }
266 struct sched_param param;
267 if (pthread_attr_getschedparam(&attr, &param) != 0) {
268 LOG(LS_ERROR) << "pthread_attr_getschedparam";
269 } else {
270 // The numbers here are arbitrary.
271 if (priority_ == PRIORITY_HIGH) {
272 param.sched_priority = 6; // 6 = HIGH
273 } else {
274 ASSERT(priority_ == PRIORITY_ABOVE_NORMAL);
275 param.sched_priority = 4; // 4 = ABOVE_NORMAL
276 }
277 if (pthread_attr_setschedparam(&attr, &param) != 0) {
278 LOG(LS_ERROR) << "pthread_attr_setschedparam";
279 }
280 }
281 }
282 }
283#endif // !defined(__native_client__)
284
285 int error_code = pthread_create(&thread_, &attr, PreRun, init);
286 if (0 != error_code) {
287 LOG(LS_ERROR) << "Unable to create pthread, error " << error_code;
288 return false;
289 }
fischman@webrtc.orge5063b12014-05-23 17:28:50290 running_.Set();
henrike@webrtc.orgf0488722014-05-13 18:00:26291#endif
292 return true;
293}
294
jiayl@webrtc.orgba737cb2014-09-18 16:45:21295bool Thread::WrapCurrent() {
296 return WrapCurrentWithThreadManager(ThreadManager::Instance(), true);
297}
298
299void Thread::UnwrapCurrent() {
300 // Clears the platform-specific thread-specific storage.
301 ThreadManager::Instance()->SetCurrentThread(NULL);
302#if defined(WEBRTC_WIN)
303 if (thread_ != NULL) {
304 if (!CloseHandle(thread_)) {
305 LOG_GLE(LS_ERROR) << "When unwrapping thread, failed to close handle.";
306 }
307 thread_ = NULL;
308 }
309#endif
310 running_.Reset();
311}
312
313void Thread::SafeWrapCurrent() {
314 WrapCurrentWithThreadManager(ThreadManager::Instance(), false);
315}
316
henrike@webrtc.orgf0488722014-05-13 18:00:26317void Thread::Join() {
fischman@webrtc.orge5063b12014-05-23 17:28:50318 if (running()) {
henrike@webrtc.orgf0488722014-05-13 18:00:26319 ASSERT(!IsCurrent());
jiayl@webrtc.org1fd362c2014-09-26 16:57:07320 if (Current() && !Current()->blocking_calls_allowed_) {
321 LOG(LS_WARNING) << "Waiting for the thread to join, "
322 << "but blocking calls have been disallowed";
323 }
324
henrike@webrtc.orgf0488722014-05-13 18:00:26325#if defined(WEBRTC_WIN)
jiayl@webrtc.orgba737cb2014-09-18 16:45:21326 ASSERT(thread_ != NULL);
henrike@webrtc.orgf0488722014-05-13 18:00:26327 WaitForSingleObject(thread_, INFINITE);
328 CloseHandle(thread_);
329 thread_ = NULL;
330 thread_id_ = 0;
331#elif defined(WEBRTC_POSIX)
332 void *pv;
333 pthread_join(thread_, &pv);
334#endif
fischman@webrtc.orge5063b12014-05-23 17:28:50335 running_.Reset();
henrike@webrtc.orgf0488722014-05-13 18:00:26336 }
337}
338
henrike@webrtc.org92a9bac2014-07-14 22:03:57339bool Thread::SetAllowBlockingCalls(bool allow) {
340 ASSERT(IsCurrent());
341 bool previous = blocking_calls_allowed_;
342 blocking_calls_allowed_ = allow;
343 return previous;
344}
345
346// static
347void Thread::AssertBlockingIsAllowedOnCurrentThread() {
348#ifdef _DEBUG
349 Thread* current = Thread::Current();
350 ASSERT(!current || current->blocking_calls_allowed_);
351#endif
352}
353
henrike@webrtc.orgf0488722014-05-13 18:00:26354void* Thread::PreRun(void* pv) {
355 ThreadInit* init = static_cast<ThreadInit*>(pv);
356 ThreadManager::Instance()->SetCurrentThread(init->thread);
Tommiea14f0a2015-05-18 11:51:06357 rtc::SetCurrentThreadName(init->thread->name_.c_str());
henrike@webrtc.orgf0488722014-05-13 18:00:26358#if __has_feature(objc_arc)
359 @autoreleasepool
360#elif defined(WEBRTC_MAC)
361 // Make sure the new thread has an autoreleasepool
362 ScopedAutoreleasePool pool;
363#endif
364 {
365 if (init->runnable) {
366 init->runnable->Run(init->thread);
367 } else {
368 init->thread->Run();
369 }
henrike@webrtc.orgf0488722014-05-13 18:00:26370 delete init;
371 return NULL;
372 }
373}
374
375void Thread::Run() {
376 ProcessMessages(kForever);
377}
378
379bool Thread::IsOwned() {
380 return owned_;
381}
382
383void Thread::Stop() {
384 MessageQueue::Quit();
385 Join();
386}
387
388void Thread::Send(MessageHandler *phandler, uint32 id, MessageData *pdata) {
389 if (fStop_)
390 return;
391
392 // Sent messages are sent to the MessageHandler directly, in the context
393 // of "thread", like Win32 SendMessage. If in the right context,
394 // call the handler directly.
henrike@webrtc.orgf0488722014-05-13 18:00:26395 Message msg;
396 msg.phandler = phandler;
397 msg.message_id = id;
398 msg.pdata = pdata;
399 if (IsCurrent()) {
400 phandler->OnMessage(&msg);
401 return;
402 }
403
jiayl@webrtc.org3987b6d2014-09-24 17:14:05404 AssertBlockingIsAllowedOnCurrentThread();
405
henrike@webrtc.orgf0488722014-05-13 18:00:26406 AutoThread thread;
407 Thread *current_thread = Thread::Current();
408 ASSERT(current_thread != NULL); // AutoThread ensures this
409
410 bool ready = false;
411 {
412 CritScope cs(&crit_);
henrike@webrtc.orgf0488722014-05-13 18:00:26413 _SendMessage smsg;
414 smsg.thread = current_thread;
415 smsg.msg = msg;
416 smsg.ready = &ready;
417 sendlist_.push_back(smsg);
418 }
419
420 // Wait for a reply
421
422 ss_->WakeUp();
423
424 bool waited = false;
425 crit_.Enter();
426 while (!ready) {
427 crit_.Leave();
jiayl@webrtc.org3987b6d2014-09-24 17:14:05428 // We need to limit "ReceiveSends" to |this| thread to avoid an arbitrary
429 // thread invoking calls on the current thread.
430 current_thread->ReceiveSendsFromThread(this);
henrike@webrtc.orgf0488722014-05-13 18:00:26431 current_thread->socketserver()->Wait(kForever, false);
432 waited = true;
433 crit_.Enter();
434 }
435 crit_.Leave();
436
437 // Our Wait loop above may have consumed some WakeUp events for this
438 // MessageQueue, that weren't relevant to this Send. Losing these WakeUps can
439 // cause problems for some SocketServers.
440 //
441 // Concrete example:
442 // Win32SocketServer on thread A calls Send on thread B. While processing the
443 // message, thread B Posts a message to A. We consume the wakeup for that
444 // Post while waiting for the Send to complete, which means that when we exit
445 // this loop, we need to issue another WakeUp, or else the Posted message
446 // won't be processed in a timely manner.
447
448 if (waited) {
449 current_thread->socketserver()->WakeUp();
450 }
451}
452
453void Thread::ReceiveSends() {
jiayl@webrtc.org3987b6d2014-09-24 17:14:05454 ReceiveSendsFromThread(NULL);
455}
456
457void Thread::ReceiveSendsFromThread(const Thread* source) {
henrike@webrtc.orgf0488722014-05-13 18:00:26458 // Receive a sent message. Cleanup scenarios:
459 // - thread sending exits: We don't allow this, since thread can exit
460 // only via Join, so Send must complete.
461 // - thread receiving exits: Wakeup/set ready in Thread::Clear()
462 // - object target cleared: Wakeup/set ready in Thread::Clear()
jiayl@webrtc.org3987b6d2014-09-24 17:14:05463 _SendMessage smsg;
464
henrike@webrtc.orgf0488722014-05-13 18:00:26465 crit_.Enter();
jiayl@webrtc.org3987b6d2014-09-24 17:14:05466 while (PopSendMessageFromThread(source, &smsg)) {
henrike@webrtc.orgf0488722014-05-13 18:00:26467 crit_.Leave();
jiayl@webrtc.org3987b6d2014-09-24 17:14:05468
henrike@webrtc.orgf0488722014-05-13 18:00:26469 smsg.msg.phandler->OnMessage(&smsg.msg);
jiayl@webrtc.org3987b6d2014-09-24 17:14:05470
henrike@webrtc.orgf0488722014-05-13 18:00:26471 crit_.Enter();
472 *smsg.ready = true;
473 smsg.thread->socketserver()->WakeUp();
474 }
475 crit_.Leave();
476}
477
jiayl@webrtc.org3987b6d2014-09-24 17:14:05478bool Thread::PopSendMessageFromThread(const Thread* source, _SendMessage* msg) {
479 for (std::list<_SendMessage>::iterator it = sendlist_.begin();
480 it != sendlist_.end(); ++it) {
481 if (it->thread == source || source == NULL) {
482 *msg = *it;
483 sendlist_.erase(it);
484 return true;
485 }
486 }
487 return false;
488}
489
tommi@webrtc.org7c64ed22015-03-17 14:25:37490void Thread::InvokeBegin() {
491 TRACE_EVENT_BEGIN0("webrtc", "Thread::Invoke");
492}
493
494void Thread::InvokeEnd() {
495 TRACE_EVENT_END0("webrtc", "Thread::Invoke");
496}
497
henrike@webrtc.orgf0488722014-05-13 18:00:26498void Thread::Clear(MessageHandler *phandler, uint32 id,
499 MessageList* removed) {
500 CritScope cs(&crit_);
501
502 // Remove messages on sendlist_ with phandler
503 // Object target cleared: remove from send list, wakeup/set ready
504 // if sender not NULL.
505
506 std::list<_SendMessage>::iterator iter = sendlist_.begin();
507 while (iter != sendlist_.end()) {
508 _SendMessage smsg = *iter;
509 if (smsg.msg.Match(phandler, id)) {
510 if (removed) {
511 removed->push_back(smsg.msg);
512 } else {
513 delete smsg.msg.pdata;
514 }
515 iter = sendlist_.erase(iter);
516 *smsg.ready = true;
517 smsg.thread->socketserver()->WakeUp();
518 continue;
519 }
520 ++iter;
521 }
522
523 MessageQueue::Clear(phandler, id, removed);
524}
525
526bool Thread::ProcessMessages(int cmsLoop) {
527 uint32 msEnd = (kForever == cmsLoop) ? 0 : TimeAfter(cmsLoop);
528 int cmsNext = cmsLoop;
529
530 while (true) {
531#if __has_feature(objc_arc)
532 @autoreleasepool
533#elif defined(WEBRTC_MAC)
534 // see: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html
535 // Each thread is supposed to have an autorelease pool. Also for event loops
536 // like this, autorelease pool needs to be created and drained/released
537 // for each cycle.
538 ScopedAutoreleasePool pool;
539#endif
540 {
541 Message msg;
542 if (!Get(&msg, cmsNext))
543 return !IsQuitting();
544 Dispatch(&msg);
545
546 if (cmsLoop != kForever) {
547 cmsNext = TimeUntil(msEnd);
548 if (cmsNext < 0)
549 return true;
550 }
551 }
552 }
553}
554
jiayl@webrtc.orgba737cb2014-09-18 16:45:21555bool Thread::WrapCurrentWithThreadManager(ThreadManager* thread_manager,
556 bool need_synchronize_access) {
fischman@webrtc.orge5063b12014-05-23 17:28:50557 if (running())
henrike@webrtc.orgf0488722014-05-13 18:00:26558 return false;
jiayl@webrtc.orgba737cb2014-09-18 16:45:21559
henrike@webrtc.orgf0488722014-05-13 18:00:26560#if defined(WEBRTC_WIN)
jiayl@webrtc.orgba737cb2014-09-18 16:45:21561 if (need_synchronize_access) {
562 // We explicitly ask for no rights other than synchronization.
563 // This gives us the best chance of succeeding.
564 thread_ = OpenThread(SYNCHRONIZE, FALSE, GetCurrentThreadId());
565 if (!thread_) {
566 LOG_GLE(LS_ERROR) << "Unable to get handle to thread.";
567 return false;
568 }
569 thread_id_ = GetCurrentThreadId();
henrike@webrtc.orgf0488722014-05-13 18:00:26570 }
henrike@webrtc.orgf0488722014-05-13 18:00:26571#elif defined(WEBRTC_POSIX)
572 thread_ = pthread_self();
573#endif
jiayl@webrtc.orgba737cb2014-09-18 16:45:21574
henrike@webrtc.orgf0488722014-05-13 18:00:26575 owned_ = false;
fischman@webrtc.orge5063b12014-05-23 17:28:50576 running_.Set();
henrike@webrtc.orgf0488722014-05-13 18:00:26577 thread_manager->SetCurrentThread(this);
578 return true;
579}
580
henrike@webrtc.orgf0488722014-05-13 18:00:26581AutoThread::AutoThread(SocketServer* ss) : Thread(ss) {
582 if (!ThreadManager::Instance()->CurrentThread()) {
583 ThreadManager::Instance()->SetCurrentThread(this);
584 }
585}
586
587AutoThread::~AutoThread() {
588 Stop();
589 if (ThreadManager::Instance()->CurrentThread() == this) {
590 ThreadManager::Instance()->SetCurrentThread(NULL);
591 }
592}
593
594#if defined(WEBRTC_WIN)
595void ComThread::Run() {
596 HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
597 ASSERT(SUCCEEDED(hr));
598 if (SUCCEEDED(hr)) {
599 Thread::Run();
600 CoUninitialize();
601 } else {
602 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr;
603 }
604}
605#endif
606
607} // namespace rtc