From 8fb0d6ddc5b9030094a3d5fa080a1cf5a1a38b4b Mon Sep 17 00:00:00 2001 From: rogerman Date: Sat, 3 Mar 2018 20:41:23 -0800 Subject: [PATCH] Windows Port: Reduce CPU usage while the emulator is idle. --- desmume/src/frontend/windows/main.cpp | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 4b13012cc..5098e6333 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -2082,14 +2082,31 @@ void displayProc() } -void displayThread(void*) +void displayThread(void *arg) { - for(;;) { - if(display_die) return; + do + { + if ( (MainWindow == NULL) || IsMinimized(MainWindow->getHWnd()) ) + { + WaitForSingleObject(display_wakeup_event, INFINITE); + } + else if ( (emu_paused || !execute || !romloaded) && (!HudEditorMode && !CommonSettings.hud.ShowInputDisplay && !CommonSettings.hud.ShowGraphicalInputDisplay) ) + { + WaitForSingleObject(display_wakeup_event, 250); + } + else + { + WaitForSingleObject(display_wakeup_event, 10); + } + + if (display_die) + { + break; + } + displayProc(); - //Sleep(10); //don't be greedy and use a whole cpu core, but leave room for 60fps - WaitForSingleObject(display_wakeup_event, 10); // same as sleep but lets something wake us up early - } + + } while (!display_die); } void KillDisplay() @@ -2135,6 +2152,8 @@ void Display() memcpy(db.buffer,dispInfo.masterCustomBuffer,targetSize); slock_unlock(display_mutex); + + SetEvent(display_wakeup_event); } } @@ -5090,6 +5109,7 @@ DOKEYDOWN: UpdateWndRects(hwnd); MainWindowToolbar->OnSize(); + SetEvent(display_wakeup_event); } break; }