Change: [Linkgraph] Pause the game when linkgraph jobs lag (#6470)
Check if the job is still running two date fract ticks before it is due to join, and if so pause the game until its done. When loading a game, check if the game would block immediately due to a job which is scheduled to be joined within two date fract ticks, and if so pause the game until its done. This avoids the main thread being blocked on a thread join, which appears to the user as if the game is unresponsive, as the UI does not repaint and cannot be interacted with. Show if pause is due to link graph job in status bar, update network messages. This does not apply for network clients.
This commit is contained in:

committed by
Patric Stout

parent
9a45a0f535
commit
0c5dc5d41e
@@ -13,6 +13,7 @@
|
||||
#include "../thread.h"
|
||||
#include "linkgraph.h"
|
||||
#include <list>
|
||||
#include <atomic>
|
||||
|
||||
class LinkGraphJob;
|
||||
class Path;
|
||||
@@ -61,6 +62,7 @@ protected:
|
||||
Date join_date; ///< Date when the job is to be joined.
|
||||
NodeAnnotationVector nodes; ///< Extra node data necessary for link graph calculation.
|
||||
EdgeAnnotationMatrix edges; ///< Extra edge data necessary for link graph calculation.
|
||||
std::atomic<bool> job_completed; ///< Is the job still running. This is accessed by multiple threads and reads may be stale.
|
||||
|
||||
void EraseFlows(NodeID from);
|
||||
void JoinThread();
|
||||
@@ -265,18 +267,25 @@ public:
|
||||
* settings have to be brutally const-casted in order to populate them.
|
||||
*/
|
||||
LinkGraphJob() : settings(_settings_game.linkgraph),
|
||||
join_date(INVALID_DATE) {}
|
||||
join_date(INVALID_DATE), job_completed(false) {}
|
||||
|
||||
LinkGraphJob(const LinkGraph &orig);
|
||||
~LinkGraphJob();
|
||||
|
||||
void Init();
|
||||
|
||||
/**
|
||||
* Check if job has actually finished.
|
||||
* This is allowed to spuriously return an incorrect value.
|
||||
* @return True if job has actually finished.
|
||||
*/
|
||||
inline bool IsJobCompleted() const { return this->job_completed.load(std::memory_order_acquire); }
|
||||
|
||||
/**
|
||||
* Check if job is supposed to be finished.
|
||||
* @return True if job should be finished by now, false if not.
|
||||
*/
|
||||
inline bool IsFinished() const { return this->join_date <= _date; }
|
||||
inline bool IsScheduledToBeJoined() const { return this->join_date <= _date; }
|
||||
|
||||
/**
|
||||
* Get the date when the job should be finished.
|
||||
|
Reference in New Issue
Block a user