mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 21:10:02 -04:00
fix(progress): ensure timely exit in progress dtor
This commit is contained in:
parent
8e4ecd6a9f
commit
10cbbb3d58
@ -148,7 +148,8 @@ class progress {
|
|||||||
private:
|
private:
|
||||||
void add_context(std::shared_ptr<context> const& ctx) const;
|
void add_context(std::shared_ptr<context> const& ctx) const;
|
||||||
|
|
||||||
std::atomic<bool> running_;
|
mutable std::mutex running_mx_;
|
||||||
|
bool running_;
|
||||||
mutable std::mutex mx_;
|
mutable std::mutex mx_;
|
||||||
std::condition_variable cond_;
|
std::condition_variable cond_;
|
||||||
std::shared_ptr<status_function_type> status_fun_;
|
std::shared_ptr<status_function_type> status_fun_;
|
||||||
|
@ -38,8 +38,7 @@ progress::progress(folly::Function<void(progress&, bool)>&& func,
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
||||||
#endif
|
#endif
|
||||||
std::mutex mx_thread;
|
std::unique_lock lock(running_mx_);
|
||||||
std::unique_lock lock(mx_thread);
|
|
||||||
while (running_) {
|
while (running_) {
|
||||||
func(*this, false);
|
func(*this, false);
|
||||||
cond_.wait_for(lock, std::chrono::milliseconds(interval_ms));
|
cond_.wait_for(lock, std::chrono::milliseconds(interval_ms));
|
||||||
@ -50,7 +49,10 @@ progress::progress(folly::Function<void(progress&, bool)>&& func,
|
|||||||
|
|
||||||
progress::~progress() noexcept {
|
progress::~progress() noexcept {
|
||||||
try {
|
try {
|
||||||
|
{
|
||||||
|
std::lock_guard lock(running_mx_);
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
}
|
||||||
cond_.notify_all();
|
cond_.notify_all();
|
||||||
thread_.join();
|
thread_.join();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user