diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index c6c349711b..e8cfbae287 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -224,6 +224,7 @@ u64 GetIdleTicks() // schedule things to be executed on the main thread. void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata) { + _assert_msg_(POWERPC, !Core::IsCPUThread(), "ScheduleEvent_Threadsafe from wrong thread"); std::lock_guard lk(tsWriteLock); Event ne; ne.time = globalTimer + cyclesIntoFuture; @@ -279,6 +280,7 @@ static void AddEventToQueue(Event* ne) // than Advance void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata) { + _assert_msg_(POWERPC, Core::IsCPUThread(), "ScheduleEvent from wrong thread"); Event *ne = GetNewEvent(); ne->userdata = userdata; ne->type = event_type; diff --git a/Source/Core/Core/HW/DSP.cpp b/Source/Core/Core/HW/DSP.cpp index 124e2c92b8..11bd45005c 100644 --- a/Source/Core/Core/HW/DSP.cpp +++ b/Source/Core/Core/HW/DSP.cpp @@ -427,7 +427,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) // We make the samples ready as soon as possible void *address = Memory::GetPointer(g_audioDMA.SourceAddress); AudioCommon::SendAIBuffer((short*)address, g_audioDMA.AudioDMAControl.NumBlocks * 8); - CoreTiming::ScheduleEvent_Threadsafe(80, et_GenerateDSPInterrupt, INT_AID); + CoreTiming::ScheduleEvent(80, et_GenerateDSPInterrupt, INT_AID); } }) ); @@ -477,6 +477,7 @@ static void GenerateDSPInterrupt(u64 DSPIntType, int cyclesLate) // CALLED FROM DSP EMULATOR, POSSIBLY THREADED void GenerateDSPInterruptFromDSPEmu(DSPInterruptType type) { + // TODO: Maybe rethink this? ScheduleEvent_Threadsafe has unpredictable timing. CoreTiming::ScheduleEvent_Threadsafe_Immediate(et_GenerateDSPInterrupt, type); } @@ -543,7 +544,7 @@ static void Do_ARAM_DMA() if (instant_dma) ticksToTransfer = 0; - CoreTiming::ScheduleEvent_Threadsafe(ticksToTransfer, et_CompleteARAM); + CoreTiming::ScheduleEvent(ticksToTransfer, et_CompleteARAM); if (instant_dma) CoreTiming::ForceExceptionCheck(100); diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp index 3a25ce97b5..bd6c3e2038 100644 --- a/Source/Core/Core/HW/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVDInterface.cpp @@ -447,6 +447,7 @@ void ChangeDisc(const std::string& newFileName) std::string* _FileName = new std::string(newFileName); CoreTiming::ScheduleEvent_Threadsafe(0, ejectDisc); CoreTiming::ScheduleEvent_Threadsafe(500000000, insertDisc, (u64)_FileName); + // TODO: We shouldn't be modifying movie state from the GUI thread. if (Movie::IsRecordingInput()) { Movie::g_bDiscChange = true; diff --git a/Source/Core/Core/HW/SI.cpp b/Source/Core/Core/HW/SI.cpp index a25c956f8f..513f16da2d 100644 --- a/Source/Core/Core/HW/SI.cpp +++ b/Source/Core/Core/HW/SI.cpp @@ -492,6 +492,7 @@ void ChangeDevice(SIDevices device, int channel) { // Called from GUI, so we need to make it thread safe. // Let the hardware see no device for .5b cycles + // TODO: Calling GetDeviceType here isn't threadsafe. if (GetDeviceType(channel) != device) { CoreTiming::ScheduleEvent_Threadsafe(0, changeDevice, ((u64)channel << 32) | SIDEVICE_NONE); diff --git a/Source/Core/Core/HW/WII_IPC.cpp b/Source/Core/Core/HW/WII_IPC.cpp index a423d7a870..56019ddf51 100644 --- a/Source/Core/Core/HW/WII_IPC.cpp +++ b/Source/Core/Core/HW/WII_IPC.cpp @@ -162,7 +162,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) if (ctrl.X1) WII_IPC_HLE_Interface::EnqueueRequest(ppc_msg); WII_IPC_HLE_Interface::Update(); - CoreTiming::ScheduleEvent_Threadsafe(0, updateInterrupts, 0); + CoreTiming::ScheduleEvent(0, updateInterrupts, 0); }) ); @@ -176,7 +176,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) MMIO::ComplexWrite([](u32, u32 val) { ppc_irq_flags &= ~val; WII_IPC_HLE_Interface::Update(); - CoreTiming::ScheduleEvent_Threadsafe(0, updateInterrupts, 0); + CoreTiming::ScheduleEvent(0, updateInterrupts, 0); }) ); @@ -187,7 +187,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) if (ppc_irq_masks & INT_CAUSE_IPC_BROADWAY) // wtf? Reset(); WII_IPC_HLE_Interface::Update(); - CoreTiming::ScheduleEvent_Threadsafe(0, updateInterrupts, 0); + CoreTiming::ScheduleEvent(0, updateInterrupts, 0); }) ); @@ -228,7 +228,7 @@ void GenerateAck(u32 _Address) ctrl.Y2 = 1; INFO_LOG(WII_IPC, "GenerateAck: %08x | %08x [R:%i A:%i E:%i]", ppc_msg,_Address, ctrl.Y1, ctrl.Y2, ctrl.X1); - CoreTiming::ScheduleEvent_Threadsafe(0, updateInterrupts, 0); + CoreTiming::ScheduleEvent(0, updateInterrupts, 0); } void GenerateReply(u32 _Address) diff --git a/Source/Core/VideoCommon/PixelEngine.cpp b/Source/Core/VideoCommon/PixelEngine.cpp index f6bc26186a..afe08c7d0a 100644 --- a/Source/Core/VideoCommon/PixelEngine.cpp +++ b/Source/Core/VideoCommon/PixelEngine.cpp @@ -16,6 +16,7 @@ #include "Core/HW/ProcessorInterface.h" #include "VideoCommon/BoundingBox.h" #include "VideoCommon/CommandProcessor.h" +#include "VideoCommon/Fifo.h" #include "VideoCommon/PixelEngine.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/VideoCommon.h" @@ -299,7 +300,10 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge) } CommandProcessor::interruptTokenWaiting = true; - CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16)); + if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread || g_use_deterministic_gpu_thread) + CoreTiming::ScheduleEvent(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16)); + else + CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16)); } // SetFinish @@ -307,7 +311,10 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge) void SetFinish() { CommandProcessor::interruptFinishWaiting = true; - CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0); + if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread || g_use_deterministic_gpu_thread) + CoreTiming::ScheduleEvent(0, et_SetFinishOnMainThread, 0); + else + CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0); INFO_LOG(PIXELENGINE, "VIDEO Set Finish"); }