Allow modal progress sleep to finish early on completion
This commit is contained in:
@@ -1495,7 +1495,7 @@ void DrawDirtyBlocks()
|
|||||||
_modal_progress_work_mutex.unlock();
|
_modal_progress_work_mutex.unlock();
|
||||||
|
|
||||||
/* Wait a while and update _realtime_tick so we are given the rights */
|
/* 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__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
__atomic_add_fetch(&_realtime_tick, MODAL_PROGRESS_REDRAW_TIMEOUT, __ATOMIC_RELAXED);
|
__atomic_add_fetch(&_realtime_tick, MODAL_PROGRESS_REDRAW_TIMEOUT, __ATOMIC_RELAXED);
|
||||||
#else
|
#else
|
||||||
|
@@ -10,6 +10,14 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "progress.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"
|
#include "safeguards.h"
|
||||||
|
|
||||||
/** Are we in a modal progress or not? */
|
/** Are we in a modal progress or not? */
|
||||||
@@ -22,6 +30,9 @@ std::mutex _modal_progress_work_mutex;
|
|||||||
/** Rights for the painting. */
|
/** Rights for the painting. */
|
||||||
std::mutex _modal_progress_paint_mutex;
|
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.
|
* Set the modal progress state.
|
||||||
* @note Makes IsFirstModalProgressLoop return true for the next call.
|
* @note Makes IsFirstModalProgressLoop return true for the next call.
|
||||||
@@ -29,8 +40,11 @@ std::mutex _modal_progress_paint_mutex;
|
|||||||
*/
|
*/
|
||||||
void SetModalProgress(bool state)
|
void SetModalProgress(bool state)
|
||||||
{
|
{
|
||||||
|
_modal_progress_cv_mutex.lock();
|
||||||
_in_modal_progress = state;
|
_in_modal_progress = state;
|
||||||
_first_in_modal_loop = true;
|
_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;
|
_first_in_modal_loop = false;
|
||||||
return ret;
|
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();
|
bool IsFirstModalProgressLoop();
|
||||||
void SetModalProgress(bool state);
|
void SetModalProgress(bool state);
|
||||||
|
void SleepWhileModalProgress(int milliseconds);
|
||||||
|
|
||||||
extern std::mutex _modal_progress_work_mutex;
|
extern std::mutex _modal_progress_work_mutex;
|
||||||
extern std::mutex _modal_progress_paint_mutex;
|
extern std::mutex _modal_progress_paint_mutex;
|
||||||
|
Reference in New Issue
Block a user