From 0eaf5edbb8509e32803e567871a95f68af057455 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 15 Mar 2011 15:13:13 +0100 Subject: [PATCH] Outsource merging of two callbacks into a separate function --- src/update-cb.cc | 22 ++++++++++++++-------- src/update-cb.hh | 5 +++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/update-cb.cc b/src/update-cb.cc index 985c8452..d86b8731 100644 --- a/src/update-cb.cc +++ b/src/update-cb.cc @@ -64,18 +64,24 @@ namespace conky { return *a == *b; } + void callback_base::merge(callback_base &&other) + { + if(other.period < period) { + period = other.period; + remaining = 0; + } + assert(wait == other.wait); + unused = 0; + } + callback_base::handle callback_base::do_register_cb(const handle &h) { - const handle &ret = *callbacks.insert(h).first; + const auto &p = callbacks.insert(h); - if(h->period < ret->period) { - ret->period = h->period; - ret->remaining = 0; - } - assert(ret->wait == h->wait); - ret->unused = 0; + if(not p.second) + (*p.first)->merge(*h); - return ret; + return *p.first; } void callback_base::run() diff --git a/src/update-cb.hh b/src/update-cb.hh index 2bc8df4d..3cf86552 100644 --- a/src/update-cb.hh +++ b/src/update-cb.hh @@ -97,6 +97,11 @@ namespace conky { // to be implemented by descendant classes virtual void work() = 0; + // called when two registered objects evaulate as equal, the latter is removed + // afterwards + virtual void merge(callback_base &&); + + public: std::mutex result_mutex;