mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-06 14:09:29 +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;
|
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)
|
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) {
|
if(not p.second)
|
||||||
ret->period = h->period;
|
(*p.first)->merge(*h);
|
||||||
ret->remaining = 0;
|
|
||||||
}
|
|
||||||
assert(ret->wait == h->wait);
|
|
||||||
ret->unused = 0;
|
|
||||||
|
|
||||||
return ret;
|
return *p.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
void callback_base::run()
|
void callback_base::run()
|
||||||
|
@ -97,6 +97,11 @@ namespace conky {
|
|||||||
// to be implemented by descendant classes
|
// to be implemented by descendant classes
|
||||||
virtual void work() = 0;
|
virtual void work() = 0;
|
||||||
|
|
||||||
|
// called when two registered objects evaulate as equal, the latter is removed
|
||||||
|
// afterwards
|
||||||
|
virtual void merge(callback_base &&);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::mutex result_mutex;
|
std::mutex result_mutex;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user