From de6adbe0ba02a5a659db5f3abd809c668d146b69 Mon Sep 17 00:00:00 2001 From: kthelgason Date: Wed, 22 Feb 2017 00:42:11 -0800 Subject: [PATCH] Remove non-ARC code from the codebase. BUG=webrtc:7198 Review-Url: https://codereview.webrtc.org/2702153004 Cr-Commit-Position: refs/heads/master@{#16765} --- webrtc/base/thread.cc | 72 +++++++------------ .../objc/AppRTCMobile/mac/APPRTCAppDelegate.m | 4 -- .../audio_device/ios/audio_device_ios.mm | 4 -- webrtc/test/testsupport/iosfileutils.mm | 4 -- 4 files changed, 27 insertions(+), 57 deletions(-) diff --git a/webrtc/base/thread.cc b/webrtc/base/thread.cc index 181cdb6e2a..591253f191 100644 --- a/webrtc/base/thread.cc +++ b/webrtc/base/thread.cc @@ -10,10 +10,6 @@ #include "webrtc/base/thread.h" -#ifndef __has_feature -#define __has_feature(x) 0 // Compatibility with non-clang or LLVM compilers. -#endif // __has_feature - #if defined(WEBRTC_WIN) #include #elif defined(WEBRTC_POSIX) @@ -28,7 +24,7 @@ #include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" -#if !__has_feature(objc_arc) && (defined(WEBRTC_MAC)) +#if defined(WEBRTC_MAC) #include "webrtc/base/maccocoathreadhelper.h" #include "webrtc/base/scoped_autorelease_pool.h" #endif @@ -51,28 +47,22 @@ ThreadManager::ThreadManager() { #ifndef NO_MAIN_THREAD_WRAPPING WrapCurrentThread(); #endif -#if !__has_feature(objc_arc) && (defined(WEBRTC_MAC)) - // Under Automatic Reference Counting (ARC), you cannot use autorelease pools - // directly. Instead, you use @autoreleasepool blocks instead. Also, we are - // maintaining thread safety using immutability within context of GCD dispatch - // queues in this case. +#if defined(WEBRTC_MAC) + // This is necessary to alert the cocoa runtime of the fact that + // we are running in a multithreaded environment. InitCocoaMultiThreading(); #endif } ThreadManager::~ThreadManager() { -#if __has_feature(objc_arc) - @autoreleasepool -#elif defined(WEBRTC_MAC) +#if defined(WEBRTC_MAC) // This is called during exit, at which point apparently no NSAutoreleasePools // are available; but we might still need them to do cleanup (or we get the // "no autoreleasepool in place, just leaking" warning when exiting). ScopedAutoreleasePool pool; #endif - { - UnwrapCurrentThread(); - pthread_key_delete(key_); - } + UnwrapCurrentThread(); + pthread_key_delete(key_); } Thread *ThreadManager::CurrentThread() { @@ -316,25 +306,21 @@ void* Thread::PreRun(void* pv) { ThreadInit* init = static_cast(pv); ThreadManager::Instance()->SetCurrentThread(init->thread); rtc::SetCurrentThreadName(init->thread->name_.c_str()); -#if __has_feature(objc_arc) - @autoreleasepool -#elif defined(WEBRTC_MAC) +#if defined(WEBRTC_MAC) // Make sure the new thread has an autoreleasepool ScopedAutoreleasePool pool; #endif - { - if (init->runnable) { - init->runnable->Run(init->thread); - } else { - init->thread->Run(); - } - delete init; -#ifdef WEBRTC_WIN - return 0; -#else - return nullptr; -#endif + if (init->runnable) { + init->runnable->Run(init->thread); + } else { + init->thread->Run(); } + delete init; +#ifdef WEBRTC_WIN + return 0; +#else + return nullptr; +#endif } void Thread::Run() { @@ -497,26 +483,22 @@ bool Thread::ProcessMessages(int cmsLoop) { int cmsNext = cmsLoop; while (true) { -#if __has_feature(objc_arc) - @autoreleasepool -#elif defined(WEBRTC_MAC) +#if defined(WEBRTC_MAC) // see: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html // Each thread is supposed to have an autorelease pool. Also for event loops // like this, autorelease pool needs to be created and drained/released // for each cycle. ScopedAutoreleasePool pool; #endif - { - Message msg; - if (!Get(&msg, cmsNext)) - return !IsQuitting(); - Dispatch(&msg); + Message msg; + if (!Get(&msg, cmsNext)) + return !IsQuitting(); + Dispatch(&msg); - if (cmsLoop != kForever) { - cmsNext = static_cast(TimeUntil(msEnd)); - if (cmsNext < 0) - return true; - } + if (cmsLoop != kForever) { + cmsNext = static_cast(TimeUntil(msEnd)); + if (cmsNext < 0) + return true; } } } diff --git a/webrtc/examples/objc/AppRTCMobile/mac/APPRTCAppDelegate.m b/webrtc/examples/objc/AppRTCMobile/mac/APPRTCAppDelegate.m index 20e6c274c1..dd3f192185 100644 --- a/webrtc/examples/objc/AppRTCMobile/mac/APPRTCAppDelegate.m +++ b/webrtc/examples/objc/AppRTCMobile/mac/APPRTCAppDelegate.m @@ -8,10 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - #import "APPRTCAppDelegate.h" #import "APPRTCViewController.h" #import "WebRTC/RTCSSLAdapter.h" diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.mm b/webrtc/modules/audio_device/ios/audio_device_ios.mm index cc164f29d1..bc7ceb8458 100644 --- a/webrtc/modules/audio_device/ios/audio_device_ios.mm +++ b/webrtc/modules/audio_device/ios/audio_device_ios.mm @@ -8,10 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - #import #import diff --git a/webrtc/test/testsupport/iosfileutils.mm b/webrtc/test/testsupport/iosfileutils.mm index 04ffd0fb57..adf17a6345 100644 --- a/webrtc/test/testsupport/iosfileutils.mm +++ b/webrtc/test/testsupport/iosfileutils.mm @@ -10,10 +10,6 @@ #if defined(WEBRTC_IOS) -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - #import #include