summaryrefslogtreecommitdiffstats
path: root/src/Protocol
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-12-07 22:41:34 +0100
committerMattes D <github@xoft.cz>2014-12-07 22:41:34 +0100
commitd323c0ba7625a8ff766779392d55813b5aea79ad (patch)
treebdd693ca3b279bd02b9bf01f1909a3cec2ccaaf0 /src/Protocol
parentFixed format warning. (diff)
parentcMojangAPI: Fixed a possible problem with thread termination order. (diff)
downloadcuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.tar
cuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.tar.gz
cuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.tar.bz2
cuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.tar.lz
cuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.tar.xz
cuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.tar.zst
cuberite-d323c0ba7625a8ff766779392d55813b5aea79ad.zip
Diffstat (limited to 'src/Protocol')
-rw-r--r--src/Protocol/MojangAPI.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 67f513e44..570754204 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -161,26 +161,38 @@ class cMojangAPI::cUpdateThread :
{
typedef cIsThread super;
public:
- cUpdateThread() :
- super("cMojangAPI::cUpdateThread")
+ cUpdateThread(cMojangAPI & a_MojangAPI) :
+ super("cMojangAPI::cUpdateThread"),
+ m_MojangAPI(a_MojangAPI)
{
}
~cUpdateThread()
{
+ // Notify the thread that it should stop:
+ m_ShouldTerminate = true;
m_evtNotify.Set();
+
+ // Wait for the thread to actually finish work:
Stop();
}
protected:
+
+ /** The cMojangAPI instance to update. */
+ cMojangAPI & m_MojangAPI;
+
+ /** The event used for notifying that the thread should terminate, as well as timing. */
cEvent m_evtNotify;
+
+ // cIsThread override:
virtual void Execute(void) override
{
do
{
- cRoot::Get()->GetMojangAPI().Update();
- } while (!m_evtNotify.Wait(60 * 60 * 1000)); // Repeat every 60 minutes
+ m_MojangAPI.Update();
+ } while (!m_ShouldTerminate && !m_evtNotify.Wait(60 * 60 * 1000)); // Repeat every 60 minutes until termination request
}
} ;
@@ -197,7 +209,7 @@ cMojangAPI::cMojangAPI(void) :
m_UUIDToProfileServer(DEFAULT_UUID_TO_PROFILE_SERVER),
m_UUIDToProfileAddress(DEFAULT_UUID_TO_PROFILE_ADDRESS),
m_RankMgr(nullptr),
- m_UpdateThread(new cUpdateThread())
+ m_UpdateThread(new cUpdateThread(*this))
{
}