Clean up usage of ScheduleEvent_Threadsafe.

This commit is contained in:
magumagu 2015-01-30 14:48:23 -08:00
parent a277172b49
commit 47be9d8e6b
6 changed files with 20 additions and 8 deletions

View File

@ -224,6 +224,7 @@ u64 GetIdleTicks()
// schedule things to be executed on the main thread. // schedule things to be executed on the main thread.
void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata) void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata)
{ {
_assert_msg_(POWERPC, !Core::IsCPUThread(), "ScheduleEvent_Threadsafe from wrong thread");
std::lock_guard<std::mutex> lk(tsWriteLock); std::lock_guard<std::mutex> lk(tsWriteLock);
Event ne; Event ne;
ne.time = globalTimer + cyclesIntoFuture; ne.time = globalTimer + cyclesIntoFuture;
@ -279,6 +280,7 @@ static void AddEventToQueue(Event* ne)
// than Advance // than Advance
void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata) void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata)
{ {
_assert_msg_(POWERPC, Core::IsCPUThread(), "ScheduleEvent from wrong thread");
Event *ne = GetNewEvent(); Event *ne = GetNewEvent();
ne->userdata = userdata; ne->userdata = userdata;
ne->type = event_type; ne->type = event_type;

View File

@ -427,7 +427,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
// We make the samples ready as soon as possible // We make the samples ready as soon as possible
void *address = Memory::GetPointer(g_audioDMA.SourceAddress); void *address = Memory::GetPointer(g_audioDMA.SourceAddress);
AudioCommon::SendAIBuffer((short*)address, g_audioDMA.AudioDMAControl.NumBlocks * 8); 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 // CALLED FROM DSP EMULATOR, POSSIBLY THREADED
void GenerateDSPInterruptFromDSPEmu(DSPInterruptType type) void GenerateDSPInterruptFromDSPEmu(DSPInterruptType type)
{ {
// TODO: Maybe rethink this? ScheduleEvent_Threadsafe has unpredictable timing.
CoreTiming::ScheduleEvent_Threadsafe_Immediate(et_GenerateDSPInterrupt, type); CoreTiming::ScheduleEvent_Threadsafe_Immediate(et_GenerateDSPInterrupt, type);
} }
@ -543,7 +544,7 @@ static void Do_ARAM_DMA()
if (instant_dma) if (instant_dma)
ticksToTransfer = 0; ticksToTransfer = 0;
CoreTiming::ScheduleEvent_Threadsafe(ticksToTransfer, et_CompleteARAM); CoreTiming::ScheduleEvent(ticksToTransfer, et_CompleteARAM);
if (instant_dma) if (instant_dma)
CoreTiming::ForceExceptionCheck(100); CoreTiming::ForceExceptionCheck(100);

View File

@ -447,6 +447,7 @@ void ChangeDisc(const std::string& newFileName)
std::string* _FileName = new std::string(newFileName); std::string* _FileName = new std::string(newFileName);
CoreTiming::ScheduleEvent_Threadsafe(0, ejectDisc); CoreTiming::ScheduleEvent_Threadsafe(0, ejectDisc);
CoreTiming::ScheduleEvent_Threadsafe(500000000, insertDisc, (u64)_FileName); CoreTiming::ScheduleEvent_Threadsafe(500000000, insertDisc, (u64)_FileName);
// TODO: We shouldn't be modifying movie state from the GUI thread.
if (Movie::IsRecordingInput()) if (Movie::IsRecordingInput())
{ {
Movie::g_bDiscChange = true; Movie::g_bDiscChange = true;

View File

@ -492,6 +492,7 @@ void ChangeDevice(SIDevices device, int channel)
{ {
// Called from GUI, so we need to make it thread safe. // Called from GUI, so we need to make it thread safe.
// Let the hardware see no device for .5b cycles // Let the hardware see no device for .5b cycles
// TODO: Calling GetDeviceType here isn't threadsafe.
if (GetDeviceType(channel) != device) if (GetDeviceType(channel) != device)
{ {
CoreTiming::ScheduleEvent_Threadsafe(0, changeDevice, ((u64)channel << 32) | SIDEVICE_NONE); CoreTiming::ScheduleEvent_Threadsafe(0, changeDevice, ((u64)channel << 32) | SIDEVICE_NONE);

View File

@ -162,7 +162,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
if (ctrl.X1) if (ctrl.X1)
WII_IPC_HLE_Interface::EnqueueRequest(ppc_msg); WII_IPC_HLE_Interface::EnqueueRequest(ppc_msg);
WII_IPC_HLE_Interface::Update(); 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, u32 val) { MMIO::ComplexWrite<u32>([](u32, u32 val) {
ppc_irq_flags &= ~val; ppc_irq_flags &= ~val;
WII_IPC_HLE_Interface::Update(); 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? if (ppc_irq_masks & INT_CAUSE_IPC_BROADWAY) // wtf?
Reset(); Reset();
WII_IPC_HLE_Interface::Update(); 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; ctrl.Y2 = 1;
INFO_LOG(WII_IPC, "GenerateAck: %08x | %08x [R:%i A:%i E:%i]", INFO_LOG(WII_IPC, "GenerateAck: %08x | %08x [R:%i A:%i E:%i]",
ppc_msg,_Address, ctrl.Y1, ctrl.Y2, ctrl.X1); ppc_msg,_Address, ctrl.Y1, ctrl.Y2, ctrl.X1);
CoreTiming::ScheduleEvent_Threadsafe(0, updateInterrupts, 0); CoreTiming::ScheduleEvent(0, updateInterrupts, 0);
} }
void GenerateReply(u32 _Address) void GenerateReply(u32 _Address)

View File

@ -16,6 +16,7 @@
#include "Core/HW/ProcessorInterface.h" #include "Core/HW/ProcessorInterface.h"
#include "VideoCommon/BoundingBox.h" #include "VideoCommon/BoundingBox.h"
#include "VideoCommon/CommandProcessor.h" #include "VideoCommon/CommandProcessor.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/PixelEngine.h" #include "VideoCommon/PixelEngine.h"
#include "VideoCommon/RenderBase.h" #include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoCommon.h"
@ -299,6 +300,9 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
} }
CommandProcessor::interruptTokenWaiting = true; CommandProcessor::interruptTokenWaiting = true;
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)); CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16));
} }
@ -307,6 +311,9 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
void SetFinish() void SetFinish()
{ {
CommandProcessor::interruptFinishWaiting = true; CommandProcessor::interruptFinishWaiting = true;
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); CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0);
INFO_LOG(PIXELENGINE, "VIDEO Set Finish"); INFO_LOG(PIXELENGINE, "VIDEO Set Finish");
} }