1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

More safe way of update locking

This commit is contained in:
AlexVinS 2014-07-03 22:30:56 +04:00
parent 9b8ad51cd3
commit 74d3effa98
5 changed files with 14 additions and 10 deletions

View File

@ -83,7 +83,7 @@ enum
};
/// Central class for managing user interface logic
class CPlayerInterface : public CGameInterface, public IUpdateable
class CPlayerInterface : public CGameInterface, public ILockedUpdatable
{
public:
bool observerInDuelMode;

View File

@ -589,7 +589,7 @@ private:
};
/// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
class CGPreGame : public CIntObject, public IUpdateable
class CGPreGame : public CIntObject, public ILockedUpdatable
{
void loadGraphics();
void disposeGraphics();
@ -602,7 +602,7 @@ public:
CDefHandler *victory, *loss;
~CGPreGame();
void update();
void update() override;
void runLocked(std::function<void(IUpdateable * )> cb) override;
void openSel(CMenuScreen::EState type, CMenuScreen::EMultiMode multi = CMenuScreen::SINGLE_PLAYER);

View File

@ -8,6 +8,7 @@ class CFramerateManager;
class CGStatusBar;
class CIntObject;
class IUpdateable;
class ILockedUpdatable;
class IShowActivatable;
class IShowable;
@ -72,7 +73,7 @@ public:
std::vector<IShowable*> objsToBlit;
SDL_Event * current; //current event - can be set to nullptr to stop handling event
IUpdateable *curInt;
ILockedUpdatable *curInt;
Point lastClick;
unsigned lastClickTime;

View File

@ -4,14 +4,12 @@
#include "SDL_Extensions.h"
#include "../CMessage.h"
void IUpdateable::runLocked(std::function<void(IUpdateable*)> cb)
void ILockedUpdatable::runLocked(std::function<void(IUpdateable*)> cb)
{
boost::unique_lock<boost::recursive_mutex> lock(updateGuard);
cb(this);
}
CIntObject::CIntObject(int used_, Point pos_):
parent_m(nullptr),
active_m(0),

View File

@ -31,14 +31,19 @@ public:
class IUpdateable
{
boost::recursive_mutex updateGuard;
public:
virtual void runLocked(std::function<void(IUpdateable * )> cb);
virtual void update()=0;
virtual ~IUpdateable(){}; //d-tor
};
class ILockedUpdatable: protected IUpdateable
{
boost::recursive_mutex updateGuard;
public:
virtual void runLocked(std::function<void(IUpdateable * )> cb);
virtual ~ILockedUpdatable(){}; //d-tor
};
// Defines a show method
class IShowable
{