Pause/resume CPU/audio together

This commit is contained in:
Aaron Culliney 2015-07-04 18:17:04 -07:00
parent 20b3e25915
commit ada6d7a0be
3 changed files with 25 additions and 4 deletions

View File

@ -139,7 +139,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobje
}
} else {
nativePaused = false;
pthread_mutex_unlock(&interface_mutex);
cpu_resume();
}
}
@ -149,7 +149,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec
}
nativePaused = true;
LOG("%s", "native onPause...");
pthread_mutex_lock(&interface_mutex);
cpu_pause();
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject obj) {
@ -199,7 +200,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject
emulator_shutting_down = true;
video_shutdown();
pthread_mutex_unlock(&interface_mutex);
cpu_resume();
if (pthread_join(cpu_thread_id, NULL)) {
ERRLOG("OOPS: pthread_join of CPU thread ...");
}
@ -262,7 +263,7 @@ jboolean Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jo
if (nativePaused) {
LOG("UNPAUSING NATIVE CPU THREAD");
nativePaused = false;
pthread_mutex_unlock(&interface_mutex);
cpu_resume();
return true;
}

View File

@ -179,6 +179,16 @@ void timing_set_auto_adjust_speed(bool auto_adjust) {
_unlock_gui_thread();
}
void cpu_pause(void) {
_lock_gui_thread();
audio_pause();
}
void cpu_resume(void) {
audio_resume();
_unlock_gui_thread();
}
bool timing_should_auto_adjust_speed(void) {
double speed = alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor;
return auto_adjust_speed && (speed < CPU_SCALE_FASTEST);

View File

@ -88,6 +88,16 @@ void timing_initialize(void);
*/
void *cpu_thread(void *ignored);
/*
* Pause timing/CPU thread
*/
void cpu_pause(void);
/*
* Resume timing/CPU thread
*/
void cpu_resume(void);
/*
* checkpoints current cycle count and updates total (for timing-dependent I/O)
*/