better pthread signaling between ui and cpu threads

This commit is contained in:
Aaron Culliney 2014-03-30 11:17:12 -07:00
parent 209eb86051
commit baf9315d01
4 changed files with 11 additions and 10 deletions

View File

@ -27,7 +27,8 @@ extern unsigned char joy_button1;
/* mutex used to synchronize between cpu and main threads */
pthread_mutex_t interface_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t interface_cond = PTHREAD_COND_INITIALIZER;
pthread_cond_t ui_thread_cond = PTHREAD_COND_INITIALIZER;
pthread_cond_t cpu_thread_cond = PTHREAD_COND_INITIALIZER;
#ifdef LINUX_JOYSTICK
#include <linux/joystick.h>

View File

@ -137,7 +137,8 @@
// ----------------------------------------------------------------------------
extern pthread_mutex_t interface_mutex;
extern pthread_cond_t interface_cond;
extern pthread_cond_t cpu_thread_cond;
extern pthread_cond_t ui_thread_cond;
extern bool caps_lock;
#ifdef LINUX_JOYSTICK
@ -147,7 +148,6 @@ extern int js_offset_x, js_offset_y;
extern float js_adjustlow_x, js_adjustlow_y, js_adjusthigh_x, js_adjusthigh_y;
#endif
void enter_debugger(void);
int c_mygetch(int block);
int c_rawkey();
void c_keys_set_key(int key);

View File

@ -1082,10 +1082,10 @@ static void begin_cpu_step()
int err = 0;
do {
if ((err = pthread_cond_signal(&interface_cond))) {
if ((err = pthread_cond_signal(&cpu_thread_cond))) {
ERRLOG("pthread_cond_signal : %d", err);
}
if ((err = pthread_cond_wait(&interface_cond, &interface_mutex))) {
if ((err = pthread_cond_wait(&ui_thread_cond, &interface_mutex))) {
ERRLOG("pthread_cond_wait : %d", err);
}
@ -1094,7 +1094,7 @@ static void begin_cpu_step()
}
} while (!stepping_struct.should_break);
if ((err = pthread_cond_signal(&interface_cond))) {
if ((err = pthread_cond_signal(&cpu_thread_cond))) {
ERRLOG("pthread_cond_signal : %d", err);
}
@ -1384,7 +1384,7 @@ void c_interface_debugging() {
c_interface_exit(-1);
is_debugging = false;
if ((err = pthread_cond_signal(&interface_cond)))
if ((err = pthread_cond_signal(&cpu_thread_cond)))
{
ERRLOG("pthread_cond_signal : %d", err);
}

View File

@ -32,7 +32,7 @@ double cpu_altscale_factor = 1.0;
int gc_cycles_timer_0 = 0;
int gc_cycles_timer_1 = 0;
uint8_t emul_reinitialize;
uint8_t emul_reinitialize = 0;
pthread_t cpu_thread_id = 0;
static unsigned int g_nCyclesExecuted; // # of cycles executed up to last IO access
@ -230,10 +230,10 @@ void cpu_thread(void *dummyptr) {
debugging_cycles -= cpu65_cycle_count;
if (c_debugger_should_break() || (debugging_cycles <= 0)) {
int err = 0;
if ((err = pthread_cond_signal(&interface_cond))) {
if ((err = pthread_cond_signal(&ui_thread_cond))) {
ERRLOG("pthread_cond_signal : %d", err);
}
if ((err = pthread_cond_wait(&interface_cond, &interface_mutex))) {
if ((err = pthread_cond_wait(&cpu_thread_cond, &interface_mutex))) {
ERRLOG("pthread_cond_wait : %d", err);
}
if (debugging_cycles <= 0) {