mirror of https://github.com/PCSX2/pcsx2.git
Core: clang-format SysThreadBase.cpp
This commit is contained in:
parent
ba1497ca48
commit
9983bcfbe6
|
@ -24,9 +24,9 @@
|
|||
// (Called form outside the context of this thread)
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
SysThreadBase::SysThreadBase() :
|
||||
m_ExecMode( ExecMode_NoThreadYet )
|
||||
, m_ExecModeMutex()
|
||||
SysThreadBase::SysThreadBase()
|
||||
: m_ExecMode(ExecMode_NoThreadYet)
|
||||
, m_ExecModeMutex()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -34,11 +34,10 @@ void SysThreadBase::Start()
|
|||
{
|
||||
_parent::Start();
|
||||
|
||||
Sleep( 1 );
|
||||
Sleep(1);
|
||||
|
||||
pxAssertDev( (m_ExecMode == ExecMode_Closing) || (m_ExecMode == ExecMode_Closed),
|
||||
"Unexpected thread status during SysThread startup."
|
||||
);
|
||||
pxAssertDev((m_ExecMode == ExecMode_Closing) || (m_ExecMode == ExecMode_Closed),
|
||||
"Unexpected thread status during SysThread startup.");
|
||||
|
||||
m_sem_event.Post();
|
||||
}
|
||||
|
@ -46,13 +45,14 @@ void SysThreadBase::Start()
|
|||
|
||||
void SysThreadBase::OnStart()
|
||||
{
|
||||
if( !pxAssertDev( m_ExecMode == ExecMode_NoThreadYet, "SysSustainableThread:Start(): Invalid execution mode" ) ) return;
|
||||
if (!pxAssertDev(m_ExecMode == ExecMode_NoThreadYet, "SysSustainableThread:Start(): Invalid execution mode"))
|
||||
return;
|
||||
|
||||
m_sem_Resume.Reset();
|
||||
m_sem_ChangingExecMode.Reset();
|
||||
|
||||
FrankenMutex( m_ExecModeMutex );
|
||||
FrankenMutex( m_RunningLock );
|
||||
FrankenMutex(m_ExecModeMutex);
|
||||
FrankenMutex(m_RunningLock);
|
||||
|
||||
_parent::OnStart();
|
||||
}
|
||||
|
@ -76,29 +76,33 @@ void SysThreadBase::OnStart()
|
|||
// Suspension must cancel itself forcefully or risk crashing whatever other action is
|
||||
// in progress.
|
||||
//
|
||||
void SysThreadBase::Suspend( bool isBlocking )
|
||||
void SysThreadBase::Suspend(bool isBlocking)
|
||||
{
|
||||
if (!pxAssertDev(!IsSelf(),"Suspend/Resume are not allowed from this thread.")) return;
|
||||
if (!IsRunning()) return;
|
||||
if (!pxAssertDev(!IsSelf(), "Suspend/Resume are not allowed from this thread."))
|
||||
return;
|
||||
if (!IsRunning())
|
||||
return;
|
||||
|
||||
// shortcut ExecMode check to avoid deadlocking on redundant calls to Suspend issued
|
||||
// from Resume or OnResumeReady code.
|
||||
if( m_ExecMode == ExecMode_Closed ) return;
|
||||
if (m_ExecMode == ExecMode_Closed)
|
||||
return;
|
||||
|
||||
{
|
||||
ScopedLock locker( m_ExecModeMutex );
|
||||
ScopedLock locker(m_ExecModeMutex);
|
||||
|
||||
switch( m_ExecMode.load() )
|
||||
switch (m_ExecMode.load())
|
||||
{
|
||||
// Invalid thread state, nothing to suspend
|
||||
case ExecMode_NoThreadYet:
|
||||
// Check again -- status could have changed since above.
|
||||
case ExecMode_Closed: return;
|
||||
case ExecMode_Closed:
|
||||
return;
|
||||
|
||||
case ExecMode_Pausing:
|
||||
case ExecMode_Paused:
|
||||
if( !isBlocking )
|
||||
throw Exception::CancelEvent( L"Cannot suspend in non-blocking fashion: Another thread is pausing the VM state." );
|
||||
if (!isBlocking)
|
||||
throw Exception::CancelEvent(L"Cannot suspend in non-blocking fashion: Another thread is pausing the VM state.");
|
||||
|
||||
m_ExecMode = ExecMode_Closing;
|
||||
m_sem_Resume.Post();
|
||||
|
@ -113,11 +117,11 @@ void SysThreadBase::Suspend( bool isBlocking )
|
|||
break;
|
||||
}
|
||||
|
||||
pxAssertDev( m_ExecMode == ExecMode_Closing, "ExecMode should be nothing other than Closing..." );
|
||||
pxAssertDev(m_ExecMode == ExecMode_Closing, "ExecMode should be nothing other than Closing...");
|
||||
m_sem_event.Post();
|
||||
}
|
||||
|
||||
if( isBlocking )
|
||||
if (isBlocking)
|
||||
m_RunningLock.Wait();
|
||||
}
|
||||
|
||||
|
@ -127,22 +131,25 @@ void SysThreadBase::Suspend( bool isBlocking )
|
|||
//
|
||||
void SysThreadBase::Pause(bool debug)
|
||||
{
|
||||
if( IsSelf() || !IsRunning() ) return;
|
||||
if (IsSelf() || !IsRunning())
|
||||
return;
|
||||
|
||||
// shortcut ExecMode check to avoid deadlocking on redundant calls to Suspend issued
|
||||
// from Resume or OnResumeReady code.
|
||||
if( (m_ExecMode == ExecMode_Closed) || (m_ExecMode == ExecMode_Paused) ) return;
|
||||
if ((m_ExecMode == ExecMode_Closed) || (m_ExecMode == ExecMode_Paused))
|
||||
return;
|
||||
|
||||
{
|
||||
ScopedLock locker( m_ExecModeMutex );
|
||||
ScopedLock locker(m_ExecModeMutex);
|
||||
|
||||
// Check again -- status could have changed since above.
|
||||
if( (m_ExecMode == ExecMode_Closed) || (m_ExecMode == ExecMode_Paused) ) return;
|
||||
if ((m_ExecMode == ExecMode_Closed) || (m_ExecMode == ExecMode_Paused))
|
||||
return;
|
||||
|
||||
if( m_ExecMode == ExecMode_Opened )
|
||||
if (m_ExecMode == ExecMode_Opened)
|
||||
m_ExecMode = ExecMode_Pausing;
|
||||
|
||||
pxAssertDev( m_ExecMode == ExecMode_Pausing, "ExecMode should be nothing other than Pausing..." );
|
||||
pxAssertDev(m_ExecMode == ExecMode_Pausing, "ExecMode should be nothing other than Pausing...");
|
||||
|
||||
if (debug)
|
||||
OnPauseDebug();
|
||||
|
@ -156,12 +163,13 @@ void SysThreadBase::Pause(bool debug)
|
|||
|
||||
void SysThreadBase::PauseSelf()
|
||||
{
|
||||
if( !IsSelf() || !IsRunning() ) return;
|
||||
if (!IsSelf() || !IsRunning())
|
||||
return;
|
||||
|
||||
{
|
||||
ScopedLock locker( m_ExecModeMutex );
|
||||
ScopedLock locker(m_ExecModeMutex);
|
||||
|
||||
if( m_ExecMode == ExecMode_Opened )
|
||||
if (m_ExecMode == ExecMode_Opened)
|
||||
m_ExecMode = ExecMode_Pausing;
|
||||
|
||||
OnPause();
|
||||
|
@ -171,7 +179,8 @@ void SysThreadBase::PauseSelf()
|
|||
|
||||
void SysThreadBase::PauseSelfDebug()
|
||||
{
|
||||
if (!IsSelf() || !IsRunning()) return;
|
||||
if (!IsSelf() || !IsRunning())
|
||||
return;
|
||||
|
||||
{
|
||||
ScopedLock locker(m_ExecModeMutex);
|
||||
|
@ -200,10 +209,12 @@ void SysThreadBase::PauseSelfDebug()
|
|||
//
|
||||
void SysThreadBase::Resume()
|
||||
{
|
||||
if( IsSelf() ) return;
|
||||
if( m_ExecMode == ExecMode_Opened ) return;
|
||||
if (IsSelf())
|
||||
return;
|
||||
if (m_ExecMode == ExecMode_Opened)
|
||||
return;
|
||||
|
||||
ScopedLock locker( m_ExecModeMutex );
|
||||
ScopedLock locker(m_ExecModeMutex);
|
||||
|
||||
// Implementation Note:
|
||||
// The entire state coming out of a Wait is indeterminate because of user input
|
||||
|
@ -211,16 +222,18 @@ void SysThreadBase::Resume()
|
|||
// sanity checks against m_ExecMode/m_Running status, and if something doesn't feel
|
||||
// right, we should abort; the user may have canceled the action before it even finished.
|
||||
|
||||
switch( m_ExecMode.load() )
|
||||
switch (m_ExecMode.load())
|
||||
{
|
||||
case ExecMode_Opened: return;
|
||||
case ExecMode_Opened:
|
||||
return;
|
||||
|
||||
case ExecMode_NoThreadYet:
|
||||
{
|
||||
Start();
|
||||
if( !m_running || (m_ExecMode == ExecMode_NoThreadYet) )
|
||||
if (!m_running || (m_ExecMode == ExecMode_NoThreadYet))
|
||||
throw Exception::ThreadCreationError(this);
|
||||
if( m_ExecMode == ExecMode_Opened ) return;
|
||||
if (m_ExecMode == ExecMode_Opened)
|
||||
return;
|
||||
}
|
||||
// fall through...
|
||||
|
||||
|
@ -230,9 +243,12 @@ void SysThreadBase::Resume()
|
|||
// state before continuing...
|
||||
|
||||
m_RunningLock.Wait();
|
||||
if( !m_running ) return;
|
||||
if( (m_ExecMode != ExecMode_Closed) && (m_ExecMode != ExecMode_Paused) ) return;
|
||||
if( !GetCorePlugins().AreLoaded() ) return;
|
||||
if (!m_running)
|
||||
return;
|
||||
if ((m_ExecMode != ExecMode_Closed) && (m_ExecMode != ExecMode_Paused))
|
||||
return;
|
||||
if (!GetCorePlugins().AreLoaded())
|
||||
return;
|
||||
break;
|
||||
|
||||
case ExecMode_Paused:
|
||||
|
@ -240,8 +256,8 @@ void SysThreadBase::Resume()
|
|||
break;
|
||||
}
|
||||
|
||||
pxAssertDev( (m_ExecMode == ExecMode_Closed) || (m_ExecMode == ExecMode_Paused),
|
||||
"SysThreadBase is not in a closed/paused state? wtf!" );
|
||||
pxAssertDev((m_ExecMode == ExecMode_Closed) || (m_ExecMode == ExecMode_Paused),
|
||||
"SysThreadBase is not in a closed/paused state? wtf!");
|
||||
|
||||
OnResumeReady();
|
||||
m_ExecMode = ExecMode_Opened;
|
||||
|
@ -269,7 +285,7 @@ void SysThreadBase::OnCleanupInThread()
|
|||
}
|
||||
|
||||
void SysThreadBase::OnSuspendInThread() {}
|
||||
void SysThreadBase::OnResumeInThread( bool isSuspended ) {}
|
||||
void SysThreadBase::OnResumeInThread(bool isSuspended) {}
|
||||
|
||||
// Tests for Pause and Suspend/Close requests. If the thread is trying to be paused or
|
||||
// closed, it will enter a wait/holding pattern here in this method until the managing
|
||||
|
@ -282,16 +298,16 @@ void SysThreadBase::OnResumeInThread( bool isSuspended ) {}
|
|||
// continued execution unimpeded.
|
||||
bool SysThreadBase::StateCheckInThread()
|
||||
{
|
||||
switch( m_ExecMode.load() )
|
||||
switch (m_ExecMode.load())
|
||||
{
|
||||
|
||||
#ifdef PCSX2_DEVBUILD // optimize out handlers for these cases in release builds.
|
||||
#ifdef PCSX2_DEVBUILD // optimize out handlers for these cases in release builds.
|
||||
case ExecMode_NoThreadYet:
|
||||
// threads should never have this state set while the thread is in any way
|
||||
// active or alive. (for obvious reasons!!)
|
||||
pxFailDev( "Invalid execution state detected." );
|
||||
pxFailDev("Invalid execution state detected.");
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
case ExecMode_Opened:
|
||||
// Other cases don't need TestCancel() because its built into the various
|
||||
|
@ -309,13 +325,13 @@ bool SysThreadBase::StateCheckInThread()
|
|||
[[fallthrough]];
|
||||
|
||||
case ExecMode_Paused:
|
||||
while( m_ExecMode == ExecMode_Paused )
|
||||
while (m_ExecMode == ExecMode_Paused)
|
||||
m_sem_Resume.WaitWithoutYield();
|
||||
|
||||
m_RunningLock.Acquire();
|
||||
if( m_ExecMode != ExecMode_Closing )
|
||||
if (m_ExecMode != ExecMode_Closing)
|
||||
{
|
||||
if ( g_CDVDReset )
|
||||
if (g_CDVDReset)
|
||||
DoCDVDopen();
|
||||
g_CDVDReset = false;
|
||||
break;
|
||||
|
@ -335,11 +351,11 @@ bool SysThreadBase::StateCheckInThread()
|
|||
[[fallthrough]];
|
||||
|
||||
case ExecMode_Closed:
|
||||
while( m_ExecMode == ExecMode_Closed )
|
||||
while (m_ExecMode == ExecMode_Closed)
|
||||
m_sem_Resume.WaitWithoutYield();
|
||||
|
||||
m_RunningLock.Acquire();
|
||||
OnResumeInThread( true );
|
||||
OnResumeInThread(true);
|
||||
g_CDVDReset = false;
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue