Keep track of whether we're in the runloop or not.

This commit is contained in:
Unknown W. Brackets 2013-02-23 12:59:40 -08:00
parent 12e2a56ef2
commit 2164a7fdf9
5 changed files with 43 additions and 8 deletions

View file

@ -33,13 +33,24 @@
// HANDLE m_hStepEvent;
event m_hStepEvent;
recursive_mutex m_hStepMutex;
event m_hInactiveEvent;
recursive_mutex m_hInactiveMutex;
// This can be read and written from ANYWHERE.
volatile CoreState coreState = CORE_STEPPING;
// Note: intentionally not used for CORE_NEXTFRAME.
volatile bool coreStatePending = false;
void Core_UpdateState(CoreState newState)
{
if ((coreState == CORE_RUNNING || coreState == CORE_NEXTFRAME) && newState != CORE_RUNNING)
coreStatePending = true;
coreState = newState;
}
void Core_ErrorPause()
{
coreState = CORE_ERROR;
Core_UpdateState(CORE_ERROR);
}
void Core_Pause()
@ -56,7 +67,7 @@ void Core_Halt(const char *msg)
void Core_Stop()
{
coreState = CORE_POWERDOWN;
Core_UpdateState(CORE_POWERDOWN);
m_hStepEvent.notify_one();
}
@ -65,6 +76,16 @@ bool Core_IsStepping()
return coreState == CORE_STEPPING || coreState == CORE_POWERDOWN;
}
bool Core_IsInactive()
{
return coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME && !coreStatePending;
}
void Core_WaitInactive()
{
while (!Core_IsInactive())
m_hInactiveEvent.wait(m_hInactiveMutex);
}
void Core_RunLoop()
{
while (!coreState) {
@ -110,6 +131,10 @@ reswitch:
// We should never get here on Android.
case CORE_STEPPING:
if (coreStatePending)
m_hInactiveEvent.notify_one();
coreStatePending = false;
//1: wait for step command..
#if defined(USING_QT_UI) || defined(_DEBUG)
host->UpdateDisassembly();
@ -142,8 +167,13 @@ reswitch:
case CORE_POWERDOWN:
case CORE_ERROR:
case CORE_NEXTFRAME:
//1: Exit loop!!
if (coreStatePending)
m_hInactiveEvent.notify_one();
coreStatePending = false;
return;
case CORE_NEXTFRAME:
return;
}
}
@ -158,7 +188,7 @@ void Core_EnableStepping(bool step)
#if defined(_DEBUG)
host->SetDebugMode(true);
#endif
coreState = CORE_STEPPING;
Core_UpdateState(CORE_STEPPING);
}
else
{
@ -166,6 +196,7 @@ void Core_EnableStepping(bool step)
host->SetDebugMode(false);
#endif
coreState = CORE_RUNNING;
coreStatePending = false;
m_hStepEvent.notify_one();
}
}

View file

@ -43,5 +43,9 @@ enum CoreState
CORE_NEXTFRAME,
};
void Core_UpdateState(CoreState newState);
bool Core_IsInactive();
void Core_WaitInactive();
extern volatile CoreState coreState;

View file

@ -133,14 +133,14 @@ void CBreakPoints::AddBreakPoint(u32 _iAddress, bool temp)
void CBreakPoints::InvalidateJit(u32 _iAddress)
{
// Don't want to clear cache while running, I think?
if (MIPSComp::jit && coreState == CORE_STEPPING)
if (MIPSComp::jit && Core_IsStepping())
MIPSComp::jit->ClearCacheAt(_iAddress);
}
void CBreakPoints::InvalidateJit()
{
// Don't want to clear cache while running, I think?
if (MIPSComp::jit && coreState == CORE_STEPPING)
if (MIPSComp::jit && Core_IsStepping())
MIPSComp::jit->ClearCache();
}

View file

@ -187,7 +187,7 @@ namespace MIPSInt
void Int_Break(u32 op)
{
ERROR_LOG(CPU, "BREAK!");
coreState = CORE_STEPPING;
Core_UpdateState(CORE_STEPPING);
PC += 4;
}

View file

@ -359,7 +359,7 @@ void Jit::WriteExitDestInEAX()
// TODO: "Ignore" this so other threads can continue?
if (g_Config.bIgnoreBadMemAccess)
MOV(32, M((void*)&coreState), Imm32(CORE_ERROR));
ABI_CallFunctionA(thunks.ProtectFunction((void *) Core_UpdateState, 1), Imm32(CORE_ERROR));
JMP(asm_.dispatcherCheckCoreState, true);
}
else