Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): remove busy loop and change waitForMemoryPanicCleared to noop since it's always on main thread (8_0_X) #10894

Closed
wants to merge 6 commits into from
6 changes: 2 additions & 4 deletions iphone/TestModule/TitaniumKit.framework/Headers/TiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
#import "TiRootViewController.h"
#import "XHRBridge.h"

extern BOOL applicationInMemoryPanic;
extern BOOL applicationInMemoryPanic; // TODO: Remove in SDK 9.0+

// TODO: Remove in SDK 9.0+
TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run on main thread, or else there is a risk of deadlock!
{
while (applicationInMemoryPanic) {
[NSThread sleepForTimeInterval:0.01];
}
}

/**
Expand Down
6 changes: 2 additions & 4 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
#import "TiRootViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>

extern BOOL applicationInMemoryPanic;
extern BOOL applicationInMemoryPanic; // TODO: Remove in SDK 9.0+

// TODO: Remove in SDK 9.0+
TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run on main thread, or else there is a risk of deadlock!
{
while (applicationInMemoryPanic) {
[NSThread sleepForTimeInterval:0.01];
}
}

/**
Expand Down
15 changes: 2 additions & 13 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@

TiApp *sharedApp;

int TiDebugPort = 2525;

NSString *TITANIUM_VERSION;

extern void UIColorFlushCache();

#define SHUTDOWN_TIMEOUT_IN_SEC 3
#define TIV @"TiVerify"

BOOL applicationInMemoryPanic = NO;
BOOL applicationInMemoryPanic = NO; // TODO: Remove in SDK 9.0+

// TODO: Remove in SDK 9.0+
TI_INLINE void waitForMemoryPanicCleared(); //WARNING: This must never be run on main thread, or else there is a risk of deadlock!

@interface TiApp ()
Expand All @@ -44,11 +43,6 @@ - (void)appBoot;

@implementation TiApp

- (void)clearMemoryPanic
{
applicationInMemoryPanic = NO;
}

@synthesize window, controller;
@synthesize disableNetworkActivityIndicator;
@synthesize remoteNotification;
Expand Down Expand Up @@ -1028,12 +1022,7 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
[self tryToInvokeSelector:@selector(applicationDidReceiveMemoryWarning:)
withArguments:[NSOrderedSet orderedSetWithObject:application]];

applicationInMemoryPanic = YES;
[Webcolor flushCache];

[self performSelector:@selector(clearMemoryPanic)
withObject:nil
afterDelay:0.0];
}

- (void)applicationWillResignActive:(UIApplication *)application
Expand Down
2 changes: 0 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollMethod.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

JSValueRef KrollCallAsFunction(JSContextRef jsContext, JSObjectRef func, JSObjectRef thisObj, size_t argCount, const JSValueRef arguments[], JSValueRef *exception)
{
waitForMemoryPanicCleared();
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
KrollMethod *o = (KrollMethod *)JSObjectGetPrivate(func);
@try {
Expand Down Expand Up @@ -68,7 +67,6 @@ JSValueRef KrollCallAsFunction(JSContextRef jsContext, JSObjectRef func, JSObjec

JSValueRef KrollCallAsNamedFunction(JSContextRef jsContext, JSObjectRef func, JSObjectRef thisObj, size_t argCount, const JSValueRef arguments[], JSValueRef *exception)
{
waitForMemoryPanicCleared();
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

KrollMethod *o = (KrollMethod *)JSObjectGetPrivate(thisObj);
Expand Down
7 changes: 0 additions & 7 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ JSValueRef ConvertIdTiValue(KrollContext *context, id obj)
//
void KrollFinalizer(JSObjectRef ref)
{
waitForMemoryPanicCleared();
id o = (id)JSObjectGetPrivate(ref);

if ((o == nil) || [o isKindOfClass:[KrollContext class]]) {
Expand Down Expand Up @@ -120,7 +119,6 @@ void KrollFinalizer(JSObjectRef ref)

bool KrollDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
{
waitForMemoryPanicCleared();
id o = (id)JSObjectGetPrivate(object);
if ([o isKindOfClass:[KrollObject class]]) {
NSString *name = (NSString *)JSStringCopyCFString(kCFAllocatorDefault, propertyName);
Expand All @@ -137,7 +135,6 @@ bool KrollDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope
//
void KrollInitializer(JSContextRef ctx, JSObjectRef object)
{
waitForMemoryPanicCleared();
id o = (id)JSObjectGetPrivate(object);
if ([o isKindOfClass:[KrollContext class]]) {
return;
Expand All @@ -155,8 +152,6 @@ void KrollInitializer(JSContextRef ctx, JSObjectRef object)

bool KrollHasProperty(JSContextRef jsContext, JSObjectRef object, JSStringRef propertyName)
{
waitForMemoryPanicCleared();

// Debugger may actually try to get properties off global Kroll property (which is a special case KrollContext singleton)
id privateObject = (id)JSObjectGetPrivate(object);
if ([privateObject isKindOfClass:[KrollContext class]]) {
Expand Down Expand Up @@ -185,7 +180,6 @@ bool KrollHasProperty(JSContextRef jsContext, JSObjectRef object, JSStringRef pr
//TODO: We should fetch from the props object and shortcut some of this. Especially now that callbacks are CURRENTLY write-only.
JSValueRef KrollGetProperty(JSContextRef jsContext, JSObjectRef object, JSStringRef prop, JSValueRef *exception)
{
waitForMemoryPanicCleared();
// Debugger may actually try to get properties off global Kroll property (which is a special case KrollContext singleton)
id privateObject = (id)JSObjectGetPrivate(object);
if ([privateObject isKindOfClass:[KrollContext class]]) {
Expand Down Expand Up @@ -258,7 +252,6 @@ JSValueRef KrollGetProperty(JSContextRef jsContext, JSObjectRef object, JSString
//
bool KrollSetProperty(JSContextRef jsContext, JSObjectRef object, JSStringRef prop, JSValueRef value, JSValueRef *exception)
{
waitForMemoryPanicCleared();
id privateObject = (id)JSObjectGetPrivate(object);
if ([privateObject isKindOfClass:[KrollContext class]]) {
return false;
Expand Down