mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-29 10:08:28 +00:00
Outsource merging of two callbacks into a separate function
This commit is contained in:
parent
82d563e18a
commit
0eaf5edbb8
@ -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()
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user