wait for score-threads on shutdown

This commit is contained in:
H-M-H 2016-05-04 15:32:24 +02:00
parent 13688bbb2a
commit cd41220a44
9 changed files with 53 additions and 6 deletions

View file

@ -176,7 +176,9 @@ public:
virtual void OnInit() = 0;
virtual void OnConsoleInit() = 0;
virtual void OnMapChange(char *pNewMapName, int MapNameSize) = 0;
virtual void OnShutdown() = 0;
// FullShutdown is true if the program is about to exit (not if the map is changed)
virtual void OnShutdown(bool FullShutdown = false) = 0;
virtual void OnTick() = 0;
virtual void OnPreSnap() = 0;

View file

@ -1828,7 +1828,7 @@ int CServer::Run()
m_Fifo.Shutdown();
#endif
GameServer()->OnShutdown();
GameServer()->OnShutdown(true);
m_pMap->Unload();
if(m_pCurrentMapData)

View file

@ -2705,8 +2705,11 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
str_copy(m_aDeleteTempfile, aTemp, sizeof(m_aDeleteTempfile));
}
void CGameContext::OnShutdown()
void CGameContext::OnShutdown(bool FullShutdown)
{
if (FullShutdown)
Score()->OnShutdown();
DeleteTempfile();
Console()->ResetServerGameSettings();
Layers()->Dest();

View file

@ -197,7 +197,7 @@ public:
virtual void OnInit();
virtual void OnConsoleInit();
virtual void OnMapChange(char *pNewMapName, int MapNameSize);
virtual void OnShutdown();
virtual void OnShutdown(bool FullShutdown = false);
virtual void OnTick();
virtual void OnPreSnap();

View file

@ -65,6 +65,9 @@ public:
virtual void SaveTeam(int Team, const char* Code, int ClientID, const char* Server) = 0;
virtual void LoadTeam(const char* Code, int ClientID) = 0;
// called when the server is shut down but not on mapchange/reload
virtual void OnShutdown() = 0;
};
#endif

View file

@ -351,3 +351,8 @@ void CFileScore::LoadTeam(const char* Code, int ClientID)
str_format(aBuf, sizeof(aBuf), "Save-function not supported in file based servers");
GameServer()->SendChatTarget(ClientID, aBuf);
}
void CFileScore::OnShutdown()
{
;
}

View file

@ -84,6 +84,8 @@ public:
virtual void RandomUnfinishedMap(int ClientID, int stars);
virtual void SaveTeam(int Team, const char* Code, int ClientID, const char* Server);
virtual void LoadTeam(const char* Code, int ClientID);
virtual void OnShutdown();
};
#endif

View file

@ -23,6 +23,8 @@ const char* CSqlData::ms_pMap = 0;
bool CSqlData::ms_GameContextAvailable = false;
int CSqlData::ms_Instance = 0;
int CSqlExecData::ms_InstanceCount = 0;
CSqlScore::CSqlScore(CGameContext *pGameServer) :
m_pGameServer(pGameServer),
m_pServer(pGameServer->Server())
@ -36,7 +38,7 @@ m_pServer(pGameServer->Server())
CSqlData::ms_pMap = m_aMap;
CSqlData::ms_GameContextAvailable = true;
CSqlData::ms_Instance++;
++CSqlData::ms_Instance;
CSqlConnector::ResetReachable();
@ -50,6 +52,24 @@ CSqlScore::~CSqlScore()
CSqlData::ms_GameContextAvailable = false;
}
void CSqlScore::OnShutdown()
{
CSqlData::ms_GameContextAvailable = false;
int i = 0;
while (CSqlExecData::ms_InstanceCount != 0)
{
// print a log about every two seconds
if (i % 20 == 0)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Waiting for score-threads to complete (%d left)", CSqlExecData::ms_InstanceCount);
dbg_msg("sql", aBuf);
}
++i;
thread_sleep(100);
}
}
void CSqlScore::ExecSqlFunc(void *pUser)
{
CSqlExecData* pData = (CSqlExecData *)pUser;

View file

@ -61,10 +61,20 @@ struct CSqlExecData
m_pFuncPtr(pFuncPtr),
m_pSqlData(pSqlData),
m_ReadOnly(ReadOnly)
{}
{
++ms_InstanceCount;
}
~CSqlExecData()
{
--ms_InstanceCount;
}
bool (*m_pFuncPtr) (CSqlServer*, CSqlData *, bool);
CSqlData *m_pSqlData;
bool m_ReadOnly;
// keeps track of score-threads
static int ms_InstanceCount;
};
struct CSqlPlayerData : CSqlData
@ -190,6 +200,8 @@ public:
virtual void RandomUnfinishedMap(int ClientID, int stars);
virtual void SaveTeam(int Team, const char* Code, int ClientID, const char* Server);
virtual void LoadTeam(const char* Code, int ClientID);
virtual void OnShutdown();
};
#endif