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:
@ -1607,7 +1607,7 @@ void CPlayerInterface::update()
|
||||
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).
|
||||
// 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());
|
||||
|
||||
locked = true;
|
||||
functor(this);
|
||||
functor();
|
||||
locked = false;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ public:
|
||||
} spellbookSettings;
|
||||
|
||||
void update() override;
|
||||
void runLocked(std::function<void(IUpdateable * )> functor) override;
|
||||
void runLocked(std::function<void()> functor) override;
|
||||
void initializeHeroTownList();
|
||||
int getLastIndex(std::string namePrefix);
|
||||
|
||||
|
@ -543,10 +543,10 @@ void CGPreGame::update()
|
||||
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);
|
||||
cb(this);
|
||||
cb();
|
||||
}
|
||||
|
||||
void CGPreGame::openCampaignScreen(std::string name)
|
||||
|
@ -609,7 +609,7 @@ public:
|
||||
|
||||
~CGPreGame();
|
||||
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 openCampaignScreen(std::string name);
|
||||
|
@ -411,10 +411,12 @@ void CGuiHandler::fakeMouseMove()
|
||||
|
||||
void CGuiHandler::renderFrame()
|
||||
{
|
||||
auto doUpdate = [](IUpdateable * target)
|
||||
auto doUpdate = [this]()
|
||||
{
|
||||
if(nullptr != target)
|
||||
target -> update();
|
||||
if(nullptr != curInt)
|
||||
{
|
||||
curInt -> update();
|
||||
}
|
||||
// draw the mouse cursor and update the screen
|
||||
CCS->curh->render();
|
||||
|
||||
@ -430,7 +432,7 @@ void CGuiHandler::renderFrame()
|
||||
if(curInt)
|
||||
curInt->runLocked(doUpdate);
|
||||
else
|
||||
doUpdate(nullptr);
|
||||
doUpdate();
|
||||
|
||||
mainFPSmng->framerateDelay(); // holds a constant FPS
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
class ILockedUpdatable: public IUpdateable
|
||||
{
|
||||
public:
|
||||
virtual void runLocked(std::function<void(IUpdateable * )> cb) = 0;
|
||||
virtual void runLocked(std::function<void()> cb) = 0;
|
||||
virtual ~ILockedUpdatable(){}; //d-tor
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user