Commit da12be87 by Maarten L. Hekkelman

progress_bar consuming too much time

parent 94a38ad4
...@@ -160,6 +160,8 @@ struct progress_bar_impl ...@@ -160,6 +160,8 @@ struct progress_bar_impl
void print_progress(); void print_progress();
void print_done(); void print_done();
using time_point = std::chrono::time_point<std::chrono::system_clock>;
int64_t m_max_value; int64_t m_max_value;
std::atomic<int64_t> m_consumed; std::atomic<int64_t> m_consumed;
int64_t m_last_consumed = 0; int64_t m_last_consumed = 0;
...@@ -167,8 +169,8 @@ struct progress_bar_impl ...@@ -167,8 +169,8 @@ struct progress_bar_impl
std::string m_action, m_message; std::string m_action, m_message;
std::mutex m_mutex; std::mutex m_mutex;
std::thread m_thread; std::thread m_thread;
std::chrono::time_point<std::chrono::system_clock> time_point m_start = std::chrono::system_clock::now();
m_start = std::chrono::system_clock::now(); time_point m_last = std::chrono::system_clock::now();
bool m_stop = false; bool m_stop = false;
}; };
...@@ -191,7 +193,9 @@ void progress_bar_impl::run() ...@@ -191,7 +193,9 @@ void progress_bar_impl::run()
{ {
while (not m_stop) while (not m_stop)
{ {
if (std::chrono::system_clock::now() - m_start < 2s) auto now = std::chrono::system_clock::now();
if (now - m_start < 2s or now - m_last < 100ms)
{ {
std::this_thread::sleep_for(10ms); std::this_thread::sleep_for(10ms);
continue; continue;
...@@ -205,6 +209,7 @@ void progress_bar_impl::run() ...@@ -205,6 +209,7 @@ void progress_bar_impl::run()
print_progress(); print_progress();
printedAny = true; printedAny = true;
m_last = std::chrono::system_clock::now();
} }
} }
catch (...) catch (...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment