Explorar el Código

More safe way of update locking

AlexVinS hace 11 años
padre
commit
74d3effa98

+ 1 - 1
client/CPlayerInterface.h

@@ -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;

+ 2 - 2
client/CPreGame.h

@@ -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);
 

+ 2 - 1
client/gui/CGuiHandler.h

@@ -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;

+ 1 - 3
client/gui/CIntObject.cpp

@@ -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),

+ 8 - 3
client/gui/CIntObject.h

@@ -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
 {