From ccfc004161ab3756bfa4c4916903b0ae1ac68382 Mon Sep 17 00:00:00 2001 From: Nolan Check Date: Sat, 18 Jul 2009 06:16:24 +0000 Subject: [PATCH] CP: Replace a couple spin-waits with event signals. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3828 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/Core.cpp | 1 + Source/Core/Core/Src/HW/CommandProcessor.cpp | 19 +++++++++++++------ Source/Core/Core/Src/HW/CommandProcessor.h | 1 + Source/Core/VideoCommon/Src/Fifo.cpp | 1 + Source/PluginSpecs/pluginspecs_video.h | 3 +++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index fb76515b9c..8b0b6b9a92 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -336,6 +336,7 @@ THREAD_RETURN EmuThread(void *pArg) VideoInitialize.pUpdateInterrupts = &(CommandProcessor::UpdateInterruptsFromVideoPlugin); VideoInitialize.pMemoryBase = Memory::base; VideoInitialize.pKeyPress = Callback_KeyPress; + VideoInitialize.pSetFifoIdle = &(CommandProcessor::SetFifoIdleFromVideoPlugin); VideoInitialize.bWii = _CoreParameter.bWii; VideoInitialize.bUseDualCore = _CoreParameter.bUseDualCore; VideoInitialize.pBBox = &PixelEngine::bbox[0]; diff --git a/Source/Core/Core/Src/HW/CommandProcessor.cpp b/Source/Core/Core/Src/HW/CommandProcessor.cpp index 36c7a7ddb3..ab019c8f4a 100644 --- a/Source/Core/Core/Src/HW/CommandProcessor.cpp +++ b/Source/Core/Core/Src/HW/CommandProcessor.cpp @@ -152,6 +152,7 @@ u16 m_tokenReg; SCPFifoStruct fifo; //This one is shared between gfx thread and emulator thread static u32 fake_GPWatchdogLastToken = 0; +static Common::Event s_fifoIdleEvent; void DoState(PointerWrap &p) { @@ -191,7 +192,7 @@ void IncrementGPWDToken() void WaitForFrameFinish() { while ((fake_GPWatchdogLastToken == fifo.Fake_GPWDToken) && fifo.bFF_GPReadEnable && (fifo.CPReadWriteDistance > 0) && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint)) - Common::YieldCPU(); + s_fifoIdleEvent.MsgWait(); fake_GPWatchdogLastToken = fifo.Fake_GPWDToken; } @@ -217,18 +218,19 @@ void Init() m_tokenReg = 0; fake_GPWatchdogLastToken = 0; + memset(&fifo,0,sizeof(fifo)); fifo.CPCmdIdle = 1 ; fifo.CPReadIdle = 1; + s_fifoIdleEvent.Init(); + et_UpdateInterrupts = CoreTiming::RegisterEvent("UpdateInterrupts", UpdateInterrupts_Wrapper); } void Shutdown() { -#ifndef _WIN32 - // delete fifo.sync; -#endif + s_fifoIdleEvent.Shutdown(); } void Read16(u16& _rReturnValue, const u32 _Address) @@ -378,8 +380,8 @@ void Write16(const u16 _Value, const u32 _Address) DEBUG_LOG(COMMANDPROCESSOR, "*********************** GXSetGPFifo very soon? ***********************"); // (mb2) We don't sleep here since it could be a perf issue for super monkey ball (yup only this game IIRC) // Touching that game is a no-go so I don't want to take the risk :p - while (fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance > 0 ) - Common::YieldCPU(); + while (fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance > 0 && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint) ) + s_fifoIdleEvent.MsgWait(); } } @@ -739,4 +741,9 @@ void UpdateInterruptsFromVideoPlugin() CoreTiming::ScheduleEvent_Threadsafe(0, et_UpdateInterrupts); } +void SetFifoIdleFromVideoPlugin() +{ + s_fifoIdleEvent.Set(); +} + } // end of namespace CommandProcessor diff --git a/Source/Core/Core/Src/HW/CommandProcessor.h b/Source/Core/Core/Src/HW/CommandProcessor.h index e80a980798..0aa434cdcd 100644 --- a/Source/Core/Core/Src/HW/CommandProcessor.h +++ b/Source/Core/Core/Src/HW/CommandProcessor.h @@ -81,6 +81,7 @@ void CatchUpGPU(); void GatherPipeBursted(); void UpdateInterrupts(); void UpdateInterruptsFromVideoPlugin(); +void SetFifoIdleFromVideoPlugin(); bool AllowIdleSkipping(); diff --git a/Source/Core/VideoCommon/Src/Fifo.cpp b/Source/Core/VideoCommon/Src/Fifo.cpp index 5f1491e6ed..53974fcd41 100644 --- a/Source/Core/VideoCommon/Src/Fifo.cpp +++ b/Source/Core/VideoCommon/Src/Fifo.cpp @@ -191,6 +191,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) } Common::AtomicStore(_fifo.CPReadIdle, 1); + video_initialize.pSetFifoIdle(); } else { diff --git a/Source/PluginSpecs/pluginspecs_video.h b/Source/PluginSpecs/pluginspecs_video.h index b455049c6f..dcace79a5a 100644 --- a/Source/PluginSpecs/pluginspecs_video.h +++ b/Source/PluginSpecs/pluginspecs_video.h @@ -21,6 +21,7 @@ typedef unsigned int (*TPeekMessages)(void); typedef void (*TUpdateInterrupts)(void); typedef void (*TUpdateFPSDisplay)(const char* text); // sets the window title typedef void (*TKeyPressed)(int keycode, bool shift, bool control); // sets the window title +typedef void (*TSetFifoIdle)(); enum FieldType { @@ -82,6 +83,8 @@ typedef struct TUpdateFPSDisplay pUpdateFPSDisplay; TKeyPressed pKeyPress; + TSetFifoIdle pSetFifoIdle; + SCPFifoStruct *pCPFifo; void *pMemoryBase; bool bWii;