Simplify mobile lifecycle at the expense of holding onto audio resources

- This does not seem to be a problem with both modern and older Gingerbread devices
This commit is contained in:
Aaron Culliney 2015-09-13 14:24:17 -07:00
parent 97f8ef1f45
commit 5dadc922fd
4 changed files with 10 additions and 86 deletions

View File

@ -136,6 +136,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
_run_tests();
// CPU thread is started from testsuite (if needed)
#else
cpu_pause();
emulator_start();
#endif
}
@ -176,18 +177,10 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec
}
LOG("%s", "");
video_backend->animation_hideTouchMenu();
#if TESTING
// test driver thread is managing CPU
#else
if (isSystemPause) {
// going to background
cpu_pauseBackground();
} else {
// going to menu
cpu_pause();
}
cpu_pause();
#endif
}

View File

@ -80,6 +80,7 @@ void emulator_start(void) {
load_settings(); // user prefs
c_keys_set_key(kF8); // show credits before emulation start
#endif
video_init();
timing_startCPU();
video_main_loop();
}

View File

@ -84,9 +84,6 @@ volatile uint8_t emul_reinitialize = 1;
#ifdef AUDIO_ENABLED
bool emul_reinitialize_audio = true;
#endif
#if MOBILE_DEVICE
static bool emul_reinitialize_background = true;
#endif
static bool cpu_shutting_down = false;
pthread_t cpu_thread_id = 0;
pthread_mutex_t interface_mutex = { 0 };
@ -211,13 +208,6 @@ void cpu_pause(void) {
assert(pthread_self() != cpu_thread_id);
_LOCK_CPU_THREAD();
#if MOBILE_DEVICE
if (emul_reinitialize_background) {
RELEASE_LOG("CPU thread already paused ...");
_UNLOCK_CPU_THREAD();
return;
}
#endif
#ifdef AUDIO_ENABLED
audio_pause();
@ -225,15 +215,6 @@ void cpu_pause(void) {
is_paused = true;
}
#if MOBILE_DEVICE
void cpu_pauseBackground(void) {
assert(pthread_self() != cpu_thread_id);
_LOCK_CPU_THREAD();
emul_reinitialize_background = true;
_UNLOCK_CPU_THREAD();
}
#endif
void cpu_resume(void) {
assert(pthread_self() != cpu_thread_id);
assert(cpu_isPaused());
@ -292,45 +273,9 @@ static void *cpu_thread(void *dummyptr) {
do
{
#if MOBILE_DEVICE
#if TESTING
emul_reinitialize_background = false;
#else
if (emul_reinitialize_background) {
speaker_destroy();
MB_Destroy();
audio_shutdown();
int err = TEMP_FAILURE_RETRY(pthread_mutex_lock(&interface_mutex));
if (err) {
RELEASE_LOG("Error locking CPU mutex : %d", err);
RELEASE_BREAK();
}
is_paused = true;
emul_reinitialize_background = false;
LOG("cpu_thread : waiting for splash screen completion...");
err = pthread_cond_wait(&cpu_thread_cond, &interface_mutex);
if (err) {
RELEASE_LOG("Error waiting for CPU condition : %d", err);
RELEASE_BREAK();
}
err = TEMP_FAILURE_RETRY(pthread_mutex_unlock(&interface_mutex));
if (err) {
RELEASE_LOG("Error unlocking CPU mutex : %d", err);
RELEASE_BREAK();
}
LOG("cpu_thread : starting...");
emul_reinitialize_audio = true;
}
#endif
#endif
#ifdef AUDIO_ENABLED
pthread_mutex_lock(&interface_mutex);
if (emul_reinitialize_audio) {
emul_reinitialize_audio = false;
@ -342,6 +287,7 @@ static void *cpu_thread(void *dummyptr) {
speaker_init();
MB_Initialize();
}
pthread_mutex_unlock(&interface_mutex);
#endif
if (emul_reinitialize) {
@ -537,12 +483,6 @@ static void *cpu_thread(void *dummyptr) {
}
#endif
#if MOBILE_DEVICE
if (UNLIKELY(emul_reinitialize_background)) {
break;
}
#endif
if (UNLIKELY(cpu_shutting_down)) {
break;
}
@ -564,8 +504,11 @@ static void *cpu_thread(void *dummyptr) {
void timing_startCPU(void) {
cpu_shutting_down = false;
video_init();
pthread_create(&cpu_thread_id, NULL, (void *)&cpu_thread, (void *)NULL);
int err = TEMP_FAILURE_RETRY(pthread_create(&cpu_thread_id, NULL, (void *)&cpu_thread, (void *)NULL));
if (err) {
RELEASE_ERRLOG("pthread_create failed!");
RELEASE_BREAK();
}
}
void timing_stopCPU(void) {

View File

@ -111,19 +111,6 @@ void timing_reinitializeAudio(void);
*/
void cpu_pause(void);
#if MOBILE_DEVICE
/*
* Pause timing/CPU thread because of a system backgrounding event.
*
* This may block for a short amount of time to grab the appropriate mutex, toggle a dirty bit, and release the mutex.
* NOTE: CPU thread is not likely to actually be paused upon function return, (but will be shortly thereafter).
*
* This should also destroy/free any audio resources (speaker, mockingboard) managed by the CPU thread back to system.
* Audio resources will be automatically recreated upon call to cpu_resume()
*/
void cpu_pauseBackground(void);
#endif
/*
* Resume timing/CPU thread
*/