static void pause_throttle() { /* if (fs_emu_get_vblank_sync()) { return; } */ fs_emu_msleep(5); }
int fs_emu_run(fs_emu_main_function function) { fs_emu_log("fs_emu_run, main_function at %p\n", function); // FIXME: should wait until we are certain that the video thread is // running (i.e. wait for a status / flag) #ifdef WITH_NETPLAY // FIXME: MOVE if (fs_emu_netplay_enabled()) { fs_log("netplay is enabled\n"); fs_emu_netplay_start(); } #endif g_emulation_thread = fs_thread_create( "emulation", emulation_thread_entry, function); if (g_emulation_thread == NULL) { fs_emu_log("error starting video thread\n"); // FIXME: ERROR MESSAGE HERE // FIXME: FATAL } #ifdef FS_EMU_DRIVERS int result = fs_emu_main_loop(); #else int result = fs_ml_main_loop(); #endif fs_emu_log("fs_emu_run: main loop is done\n"); if (g_fs_emu_benchmark_start_time) { int64_t t2 = fs_emu_monotonic_time(); double ttime = ((t2 - g_fs_emu_benchmark_start_time) / 1000000.0); double sys_fps = g_fs_emu_total_sys_frames / ttime; double emu_fps = g_fs_emu_total_emu_frames / ttime; fs_log("average fps sys: %0.1f emu: %0.1f\n", sys_fps, emu_fps); } fs_emu_log("fs_emu_run: waiting for emulation thread to stop\n"); while (g_fs_emu_emulation_thread_running) { fs_emu_msleep(1); } fs_emu_log("fs_emu_run: emulation thread stopped\n"); #ifdef USE_SDL_AUDIO fs_emu_log("fs_emu_run: calling SDL_CloseAudio\n"); SDL_CloseAudio(); #endif fs_emu_audio_shutdown(); fs_emu_log("fs_emu_run: returning\n"); return result; }
static void *emulation_thread_entry(void *data) { fs_emu_log("emulation thread started\n"); g_fs_emu_emulation_thread_running = 1; #ifdef WINDOWS if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL)) { fs_emu_log("thread priority set to THREAD_PRIORITY_ABOVE_NORMAL\n"); } else { int dwError = GetLastError(); fs_emu_log("Failed to set thread priority (%d)\n", dwError); } #endif #ifdef WITH_NETPLAY if (fs_emu_netplay_enabled()) { fs_emu_log("netplay is enabled - waiting for connection\n"); while (!fs_emu_netplay_connected()) { // waiting for connection fs_emu_msleep(10); if (!fs_emu_netplay_enabled()) { // net play mode was aborted fs_emu_log("netplay aborted\n"); break; } } } #endif void (*main_function)() = data; if (main_function) { fs_emu_log("main function at %p\n", data); main_function(); } else { fs_emu_fatal("main function is NULL pointer\n"); } // call fs_ml_quit in case the quit was not explicitly requested already fs_ml_quit(); g_fs_emu_emulation_thread_running = 0; // with this set, and fs_ml_quit being called, the frame render // function will call fs_ml_stop when the fadeout effect is done g_fs_emu_emulation_thread_stopped = 1; //fs_emu_log("calling fs_ml_stop because emulation thread has ended\n"); //fs_ml_stop(); return NULL; }
static void *emulation_thread(void *data) { fse_log("[FSE] Emulation thread started\n"); #ifdef WINDOWS set_windows_thread_priority(); #endif #ifdef WITH_NETPLAY if (fs_emu_netplay_enabled()) { fse_log("[NETPLAY] Enabled - waiting for connection...\n"); while (!fs_emu_netplay_connected()) { /* Waiting for connection... */ fs_emu_msleep(10); if (!fs_emu_netplay_enabled()) { /* Net play mode was aborted. */ fse_log("netplay aborted\n"); break; } } } #endif g_fs_emu_emulation_thread_running = 1; void (*main_function)() = data; if (main_function) { fse_log("[FSE] Run main function at %p\n", data); main_function(); } else { fs_emu_fatal("[FSE] NULL pointer main function\n"); } /* Call fs_ml_quit in case quit was not explicitly requested already. */ fs_ml_quit(); g_fs_emu_emulation_thread_running = 0; /* With this set, and fs_ml_quit being called, the frame render * function will call fs_ml_stop when the fadeout effect is done. */ g_fs_emu_emulation_thread_stopped = 1; return NULL; }