Skip to content

Commit

Permalink
[MT] Fix crash/hang in 0a4ecee
Browse files Browse the repository at this point in the history
  • Loading branch information
zerver committed Dec 26, 2011
1 parent 99e8a31 commit 0cfc97c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rts/System/SpringApp.cpp
Expand Up @@ -924,7 +924,7 @@ int SpringApp::Update()
Watchdog::ClearTimer(WDT_MAIN);

if (!GML::SimThreadRunning()) {
ret = activeController->Update();
ret = GML::UpdateSim(activeController);
}

if (ret) {
Expand Down
22 changes: 12 additions & 10 deletions rts/lib/gml/gml_base.cpp
Expand Up @@ -40,39 +40,31 @@ static void gmlSimLoop(void*)
if (gmlShareLists)
ogc->WorkerThreadPost();

Threading::SetSimThread(true);
//Threading::SetAffinity(3);

Watchdog::ClearTimer(WDT_SIM);

while(gmlKeepRunning) {
if(!gmlMultiThreadSim) {
Threading::SetSimThread(false);
Watchdog::ClearTimer(WDT_SIM, true);
while(!gmlMultiThreadSim && gmlKeepRunning)
SDL_Delay(500);
Threading::SetSimThread(true);
}

//FIXME activeController could change while processing this branch. Better make it safe with a mutex?
if (activeController) {
Watchdog::ClearTimer(WDT_SIM);
gmlProcessor->ExpandAuxQueue();

{
GML_MSTMUTEX_LOCK(sim); // UpdateSim
if(!activeController->Update())
gmlKeepRunning = false;
}
if(!GML::UpdateSim(activeController))
gmlKeepRunning = false;

gmlProcessor->GetQueue();
}

boost::thread::yield();
}

Threading::SetSimThread(false);

if(gmlShareLists)
ogc->WorkerThreadFree();
}
Expand All @@ -82,6 +74,16 @@ static void gmlSimLoop(void*)
#endif

namespace GML {

bool UpdateSim(CGameController *ac) {
GML_MSTMUTEX_LOCK(sim); // UpdateSim

Threading::SetSimThread(true);
bool ret = ac->Update();
Threading::SetSimThread(false);
return ret;
}

void Init()
{
gmlShareLists = configHandler->GetBool("MultiThreadShareLists");
Expand Down
3 changes: 3 additions & 0 deletions rts/lib/gml/gml_base.h
Expand Up @@ -4,6 +4,7 @@
#define GML_BASE_H_

#include "gml.h"
#include "Game/GameController.h"

#ifdef USE_GML
namespace GML {
Expand All @@ -18,6 +19,7 @@ namespace GML {
inline int ThreadNumber() { return gmlThreadNumber; }
inline void ThreadNumber(int num) { set_threadnum(num); }
inline int ThreadCount() { return gmlThreadCount; }
bool UpdateSim(CGameController *ac);
};
#else
namespace GML {
Expand All @@ -32,6 +34,7 @@ namespace GML {
inline int ThreadNumber() { return 0; }
inline void ThreadNumber(int num) { }
inline int ThreadCount() { return 1; }
inline bool UpdateSim(CGameController *ac) { return ac->Update(); }
};
#endif

Expand Down

0 comments on commit 0cfc97c

Please sign in to comment.