summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@opera.com>2020-07-17 16:09:00 +0200
committerJoel Klinghed <the_jk@opera.com>2020-07-17 16:09:00 +0200
commit82e82c31578d7b056b831aa2b0579efc9464e501 (patch)
treea0d501f7a914d864e1bf2dbfb441637fa24fb50b /src
parentefc0c2cbcdedad5675ba02ef6f4755d030499ffd (diff)
Use less CPU in goma
Only re-draw when something changes and update once per 5 sec
Diffstat (limited to 'src')
-rw-r--r--src/goma.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/goma.cc b/src/goma.cc
index c82920d..47f0a43 100644
--- a/src/goma.cc
+++ b/src/goma.cc
@@ -28,6 +28,14 @@ struct State {
std::string msg_;
uint64_t running_{0};
uint64_t failed_{0};
+
+ bool operator==(State const& state) const {
+ if (error_ != state.error_)
+ return false;
+ if (error_)
+ return msg_ == state.msg_;
+ return running_ == state.running_ && failed_ == state.failed_;
+ }
};
class GomaPoll {
@@ -86,9 +94,11 @@ private:
{
std::unique_lock<std::mutex> lock(mutex_);
- state_ = state;
- io::write(pipe_, "s", 1);
- cond_.wait_for(lock, std::chrono::seconds(1));
+ if (!(state_ == state)) {
+ state_ = state;
+ io::write(pipe_, "s", 1);
+ }
+ cond_.wait_for(lock, std::chrono::seconds(5));
if (quit_)
break;
}