Pause the game instead of blocking when link graph jobs lag.

Check if the job is still running one date fract tick before it
is due to join and if so pause the game until its done.
This avoids the main thread being blocked on a thread join.
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:
Jonathan G Rennison
2015-09-03 18:36:30 +01:00
parent 5108a71240
commit c6854afcef
10 changed files with 86 additions and 4 deletions

View File

@@ -40,7 +40,8 @@ LinkGraphJob::LinkGraphJob(const LinkGraph &orig) :
link_graph(orig),
settings(_settings_game.linkgraph),
thread(NULL),
join_date(_date + _settings_game.linkgraph.recalc_time)
join_date(_date + _settings_game.linkgraph.recalc_time),
job_completed(false)
{
}
@@ -171,6 +172,20 @@ LinkGraphJob::~LinkGraphJob()
}
}
/**
* Check if job has actually finished.
* This is allowed to spuriously return an incorrect value.
* @return True if job has actually finished.
*/
bool LinkGraphJob::IsJobCompleted() const
{
#if defined(__GNUC__) && (__cplusplus >= 201103L || defined(__STDCXX_VERSION__) || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__))
return __atomic_load_n(&job_completed, __ATOMIC_RELAXED);
#else
return job_completed;
#endif
}
/**
* Initialize the link graph job: Resize nodes and edges and populate them.
* This is done after the constructor so that we can do it in the calculation