mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-10-31 15:20:10 +00:00
Allow modal progress sleep to finish early on completion
This commit is contained in:
parent
e2ab622a14
commit
c061675001
@ -1495,7 +1495,7 @@ void DrawDirtyBlocks()
|
||||
_modal_progress_work_mutex.unlock();
|
||||
|
||||
/* Wait a while and update _realtime_tick so we are given the rights */
|
||||
if (!is_first_modal_progress_loop) CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT);
|
||||
if (!is_first_modal_progress_loop) SleepWhileModalProgress(MODAL_PROGRESS_REDRAW_TIMEOUT);
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
__atomic_add_fetch(&_realtime_tick, MODAL_PROGRESS_REDRAW_TIMEOUT, __ATOMIC_RELAXED);
|
||||
#else
|
||||
|
@ -10,6 +10,14 @@
|
||||
#include "stdafx.h"
|
||||
#include "progress.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#if defined(__MINGW32__)
|
||||
#include "3rdparty/mingw-std-threads/mingw.mutex.h"
|
||||
#include "3rdparty/mingw-std-threads/mingw.condition_variable.h"
|
||||
#endif
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
/** Are we in a modal progress or not? */
|
||||
@ -22,6 +30,9 @@ std::mutex _modal_progress_work_mutex;
|
||||
/** Rights for the painting. */
|
||||
std::mutex _modal_progress_paint_mutex;
|
||||
|
||||
static std::mutex _modal_progress_cv_mutex;
|
||||
static std::condition_variable _modal_progress_cv;
|
||||
|
||||
/**
|
||||
* Set the modal progress state.
|
||||
* @note Makes IsFirstModalProgressLoop return true for the next call.
|
||||
@ -29,8 +40,11 @@ std::mutex _modal_progress_paint_mutex;
|
||||
*/
|
||||
void SetModalProgress(bool state)
|
||||
{
|
||||
_modal_progress_cv_mutex.lock();
|
||||
_in_modal_progress = state;
|
||||
_first_in_modal_loop = true;
|
||||
_modal_progress_cv_mutex.unlock();
|
||||
if (!state) _modal_progress_cv.notify_all();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,3 +58,9 @@ bool IsFirstModalProgressLoop()
|
||||
_first_in_modal_loop = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SleepWhileModalProgress(int milliseconds)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(_modal_progress_cv_mutex);
|
||||
_modal_progress_cv.wait_for(lk, std::chrono::milliseconds(milliseconds), []{ return !_in_modal_progress; });
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ static inline bool UseThreadedModelProgress()
|
||||
|
||||
bool IsFirstModalProgressLoop();
|
||||
void SetModalProgress(bool state);
|
||||
void SleepWhileModalProgress(int milliseconds);
|
||||
|
||||
extern std::mutex _modal_progress_work_mutex;
|
||||
extern std::mutex _modal_progress_paint_mutex;
|
||||
|
Loading…
Reference in New Issue
Block a user