From f3d5a44e76183da57dfc29d27e2d4f5df7da5d78 Mon Sep 17 00:00:00 2001 From: meancoot Date: Sat, 21 Dec 2013 21:58:19 -0500 Subject: [PATCH] (Apple - No Thread) Fix performance regression. --- apple/OSX/platform.m | 4 ++++ apple/OSX/settings.m | 3 +++ apple/common/RetroArch_Apple.h | 2 ++ apple/common/main.m | 38 ++++++++++++++++++++++++++++++ apple/iOS/platform.m | 2 ++ frontend/platform/platform_apple.c | 32 ++----------------------- 6 files changed, 51 insertions(+), 30 deletions(-) diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 06483f1c41..ca47e0fd74 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -247,10 +247,14 @@ static void* const associated_core_key = (void*)&associated_core_key; { if (file) [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:BOXSTRING(file)]]; + + apple_start_iteration(); } - (void)unloadingCore:(const NSString*)core { + apple_stop_iteration(); + if (_isTerminating) [[NSApplication sharedApplication] terminate:nil]; diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 29b46be810..44f60efbe5 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -186,12 +186,15 @@ static void* const associated_name_tag = (void*)&associated_name_tag; } setting_data_load_config_path(setting_data_get_list(), [apple_platform.globalConfigFile UTF8String]); + apple_stop_iteration(); } - (void)windowWillClose:(NSNotification *)notification { setting_data_save_config_path(setting_data_get_list(), [apple_platform.globalConfigFile UTF8String]); [NSApp stopModal]; + + apple_start_iteration(); } #pragma mark Section Table diff --git a/apple/common/RetroArch_Apple.h b/apple/common/RetroArch_Apple.h index ca2612b162..2eb916ce77 100644 --- a/apple/common/RetroArch_Apple.h +++ b/apple/common/RetroArch_Apple.h @@ -54,6 +54,8 @@ extern id apple_platform; // main.m extern void apple_run_core(NSString* core, const char* file); +extern void apple_start_iteration(); +extern void apple_stop_iteration(); // utility.m extern void apple_display_alert(NSString* message, NSString* title); diff --git a/apple/common/main.m b/apple/common/main.m index 783d6cd259..6cc8be6d01 100644 --- a/apple/common/main.m +++ b/apple/common/main.m @@ -30,6 +30,44 @@ bool apple_is_running; bool apple_use_tv_mode; NSString* apple_core; +static CFRunLoopObserverRef iterate_observer; + +static void do_iteration() +{ + if (iterate_observer) + { + if (apple_rarch_iterate_once()) + { + CFRunLoopObserverInvalidate(iterate_observer); + CFRelease(iterate_observer); + iterate_observer = 0; + + apple_rarch_exited(false); + } + else + CFRunLoopWakeUp(CFRunLoopGetMain()); + } +} + +void apple_start_iteration() +{ + if (!iterate_observer) + { + iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting, true, 0, do_iteration, 0); + CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes); + } +} + +void apple_stop_iteration() +{ + if (iterate_observer) + { + CFRunLoopObserverInvalidate(iterate_observer); + CFRelease(iterate_observer); + iterate_observer = 0; + } +} + void apple_run_core(NSString* core, const char* file) { if (!apple_is_running) diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index f1f27428ff..4c2d1c53f2 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -268,10 +268,12 @@ static void handle_touch_event(NSArray* touches) [[UIApplication sharedApplication] setIdleTimerDisabled:true]; [_window setRootViewController:[RAGameView get]]; g_extern.is_paused = false; + apple_start_iteration(); } - (IBAction)showPauseMenu:(id)sender { + apple_stop_iteration(); g_extern.is_paused = true; [[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationNone]; [[UIApplication sharedApplication] setIdleTimerDisabled:false]; diff --git a/frontend/platform/platform_apple.c b/frontend/platform/platform_apple.c index 079913476f..4009ac6ebc 100644 --- a/frontend/platform/platform_apple.c +++ b/frontend/platform/platform_apple.c @@ -14,8 +14,6 @@ * If not, see . */ -#include - #include "../menu/menu_common.h" #include "../../apple/common/rarch_wrapper.h" #include "../../apple/common/apple_export.h" @@ -28,7 +26,7 @@ #include #include -static CFRunLoopObserverRef iterate_observer; +extern bool apple_is_running; void apple_event_basic_command(enum basic_event_t action) { @@ -56,7 +54,7 @@ void apple_refresh_config() memset(g_settings.input.overlay, 0, sizeof(g_settings.input.overlay)); memset(g_settings.video.shader_path, 0, sizeof(g_settings.video.shader_path)); - if (iterate_observer) + if (apple_is_running) { uninit_drivers(); config_load(); @@ -64,31 +62,8 @@ void apple_refresh_config() } } -static void do_iteration() -{ - if (iterate_observer) - { - if (apple_rarch_iterate_once()) - { - CFRunLoopObserverInvalidate(iterate_observer); - CFRelease(iterate_observer); - iterate_observer = 0; - - apple_rarch_exited(false); - } - else - CFRunLoopWakeUp(CFRunLoopGetMain()); - } -} - int apple_rarch_load_content(int argc, char* argv[]) { - if (iterate_observer) - { - RARCH_ERR("apple_rarch_load_content called while content is still running."); - return 1; - } - rarch_main_clear_state(); rarch_init_msg_queue(); @@ -98,9 +73,6 @@ int apple_rarch_load_content(int argc, char* argv[]) menu_init(); g_extern.lifecycle_state |= 1ULL << MODE_GAME; g_extern.lifecycle_state |= 1ULL << MODE_GAME_ONESHOT; - - iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting, true, 0, do_iteration, 0); - CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes); return 0; }