2050: Fix race condition. Closes #2004 r=def- a=Learath2

I guess a new state is better then a global variable

Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
bors[bot] 2020-01-26 15:49:30 +00:00 committed by GitHub
commit 72fcf9caa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -71,6 +71,7 @@ public:
STATE_ONLINE,
STATE_DEMOPLAYBACK,
STATE_QUITING,
STATE_RESTARTING,
};
//

View file

@ -552,7 +552,7 @@ int *CClient::GetDirectInput(int Tick)
// ------ state handling -----
void CClient::SetState(int s)
{
if(m_State == IClient::STATE_QUITING)
if(m_State == IClient::STATE_QUITING || m_State == IClient::STATE_RESTARTING)
return;
int Old = m_State;
@ -1021,9 +1021,7 @@ void CClient::DebugRender()
void CClient::Restart()
{
char aBuf[512];
shell_execute(Storage()->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
Quit();
SetState(IClient::STATE_RESTARTING);
}
void CClient::Quit()
@ -2371,7 +2369,7 @@ void CClient::PumpNetwork()
if(State() != IClient::STATE_DEMOPLAYBACK)
{
// check for errors
if(State() != IClient::STATE_OFFLINE && State() != IClient::STATE_QUITING && m_NetClient[CLIENT_MAIN].State() == NETSTATE_OFFLINE)
if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITING && m_NetClient[CLIENT_MAIN].State() == NETSTATE_OFFLINE)
{
SetState(IClient::STATE_OFFLINE);
Disconnect();
@ -3089,7 +3087,7 @@ void CClient::Run()
AutoCSV_Cleanup();
// check conditions
if(State() == IClient::STATE_QUITING)
if(State() == IClient::STATE_QUITING || State() == IClient::STATE_RESTARTING)
break;
#if defined(CONF_FAMILY_UNIX)
@ -4064,10 +4062,18 @@ int main(int argc, const char **argv) // ignore_convention
// write down the config and quit
pConfig->Save();
delete pKernel;
bool Restarting = pClient->State() == CClient::STATE_RESTARTING;
pClient->~CClient();
free(pClient);
if(Restarting)
{
char aBuf[512];
shell_execute(pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
}
delete pKernel;
return 0;
}