mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 20:41:04 -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:
|
||||
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_;
|
||||
std::condition_variable cond_;
|
||||
std::shared_ptr<status_function_type> status_fun_;
|
||||
|
@ -38,8 +38,7 @@ progress::progress(folly::Function<void(progress&, bool)>&& func,
|
||||
#ifdef _WIN32
|
||||
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
||||
#endif
|
||||
std::mutex mx_thread;
|
||||
std::unique_lock lock(mx_thread);
|
||||
std::unique_lock lock(running_mx_);
|
||||
while (running_) {
|
||||
func(*this, false);
|
||||
cond_.wait_for(lock, std::chrono::milliseconds(interval_ms));
|
||||
@ -50,7 +49,10 @@ progress::progress(folly::Function<void(progress&, bool)>&& func,
|
||||
|
||||
progress::~progress() noexcept {
|
||||
try {
|
||||
running_ = false;
|
||||
{
|
||||
std::lock_guard lock(running_mx_);
|
||||
running_ = false;
|
||||
}
|
||||
cond_.notify_all();
|
||||
thread_.join();
|
||||
} catch (...) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user