diff options
| author | Joel Klinghed <the_jk@opera.com> | 2020-07-17 16:09:00 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@opera.com> | 2020-07-17 16:09:00 +0200 |
| commit | 82e82c31578d7b056b831aa2b0579efc9464e501 (patch) | |
| tree | a0d501f7a914d864e1bf2dbfb441637fa24fb50b | |
| parent | efc0c2cbcdedad5675ba02ef6f4755d030499ffd (diff) | |
Use less CPU in goma
Only re-draw when something changes and update once per 5 sec
| -rw-r--r-- | src/goma.cc | 16 |
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; } |
