1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

Conurrency related tweaks. Crashes in renderFrame should be fixed, but synchronization is still not perfect

This commit is contained in:
AlexVinS
2015-02-15 04:53:01 +03:00
parent b71d985d49
commit c46999bcb8
6 changed files with 13 additions and 11 deletions

View File

@ -1607,7 +1607,7 @@ void CPlayerInterface::update()
GH.drawFPSCounter(); GH.drawFPSCounter();
} }
void CPlayerInterface::runLocked(std::function<void(IUpdateable * )> functor) void CPlayerInterface::runLocked(std::function<void()> functor)
{ {
// Updating GUI requires locking pim mutex (that protects screen and GUI state). // Updating GUI requires locking pim mutex (that protects screen and GUI state).
// When ending the game, the pim mutex might be hold by other thread, // When ending the game, the pim mutex might be hold by other thread,
@ -1635,7 +1635,7 @@ void CPlayerInterface::runLocked(std::function<void(IUpdateable * )> functor)
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex()); boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
locked = true; locked = true;
functor(this); functor();
locked = false; locked = false;
} }

View File

@ -134,7 +134,7 @@ public:
} spellbookSettings; } spellbookSettings;
void update() override; void update() override;
void runLocked(std::function<void(IUpdateable * )> functor) override; void runLocked(std::function<void()> functor) override;
void initializeHeroTownList(); void initializeHeroTownList();
int getLastIndex(std::string namePrefix); int getLastIndex(std::string namePrefix);

View File

@ -543,10 +543,10 @@ void CGPreGame::update()
GH.drawFPSCounter(); GH.drawFPSCounter();
} }
void CGPreGame::runLocked(std::function<void(IUpdateable * )> cb) void CGPreGame::runLocked(std::function<void()> cb)
{ {
boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim); boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
cb(this); cb();
} }
void CGPreGame::openCampaignScreen(std::string name) void CGPreGame::openCampaignScreen(std::string name)

View File

@ -609,7 +609,7 @@ public:
~CGPreGame(); ~CGPreGame();
void update() override; void update() override;
void runLocked(std::function<void(IUpdateable * )> cb) override; void runLocked(std::function<void()> cb) override;
void openSel(CMenuScreen::EState type, CMenuScreen::EMultiMode multi = CMenuScreen::SINGLE_PLAYER); void openSel(CMenuScreen::EState type, CMenuScreen::EMultiMode multi = CMenuScreen::SINGLE_PLAYER);
void openCampaignScreen(std::string name); void openCampaignScreen(std::string name);

View File

@ -411,10 +411,12 @@ void CGuiHandler::fakeMouseMove()
void CGuiHandler::renderFrame() void CGuiHandler::renderFrame()
{ {
auto doUpdate = [](IUpdateable * target) auto doUpdate = [this]()
{ {
if(nullptr != target) if(nullptr != curInt)
target -> update(); {
curInt -> update();
}
// draw the mouse cursor and update the screen // draw the mouse cursor and update the screen
CCS->curh->render(); CCS->curh->render();
@ -430,7 +432,7 @@ void CGuiHandler::renderFrame()
if(curInt) if(curInt)
curInt->runLocked(doUpdate); curInt->runLocked(doUpdate);
else else
doUpdate(nullptr); doUpdate();
mainFPSmng->framerateDelay(); // holds a constant FPS mainFPSmng->framerateDelay(); // holds a constant FPS
} }

View File

@ -41,7 +41,7 @@ public:
class ILockedUpdatable: public IUpdateable class ILockedUpdatable: public IUpdateable
{ {
public: public:
virtual void runLocked(std::function<void(IUpdateable * )> cb) = 0; virtual void runLocked(std::function<void()> cb) = 0;
virtual ~ILockedUpdatable(){}; //d-tor virtual ~ILockedUpdatable(){}; //d-tor
}; };