-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Schedule.h|cpp refactored to class templates for performance and reuse #6902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@dok-net : |
560d917
to
e35d6fb
Compare
@hreintke I've tried for a few minutes to wrap
Instead of the active field in SomeClass, you might instead derive from |
@dok-net : Main functionality of CallBacklist is that it prevents executing the callback when the Object that registered the callback is already destructed. Do not (yet) see that possibility in (Multi)Delegate. |
6680cae
to
ff4bdd6
Compare
36b3353
to
e7a2b49
Compare
2c11ba9
to
ad94655
Compare
d523639
to
2eec43a
Compare
3e24043
to
24b446f
Compare
c08978d
to
8ef1041
Compare
8ef1041
to
ce88779
Compare
…ATTR attribute. This affects the unnamed namespace or static non-member functions.
…uto-remove. Invoke returns result of last Delegate call. Caveat: breaks use of event multiplexer with auto-remove; WIP: add iterators.
WIP: remove() during iteration.
…ent operators, needing a lot of code duplication, this commit provides that.
This reverts commit 7c9c23e.
(cherry picked from commit 7c9c23e)
…son of Delegate<> vs. std::function<>
…rom Git commit history.
…ate non-queue (event multiplexer) mode.
78d2073
to
3458547
Compare
The interrupt/signal safe linked list in
Schedule.h|cpp
can very well be used as a universal queue or event delegate (c# terminology ;-) ) class.This PR also supersedes
cores/esp8266/CallbackList.h
.The new
Delegate.h
class template provides compelling performance improvements in cases wherestd::function
is repeatedly constructed during execution, which is quite slow. While a simple seek&replace drop-in forstd::function
in APIs, call sites can in turn be refactored; basically, the binding via lambda capture orstd::bind
is substituted for by using the C-function pointer styleDelegate
constructor'sobj
argument.Performance comparisons:
Using C function pointer or
std::function
One assignment and one call via
bool(*f)(Foo*, int)
: 108 cycles; call only: 31 cycles.One assignment and one call via
std::function<bool(int)>
: 1360 cycles; call only: 34 cycles.Using
Delegate<bool(int), Foo*>
One assignment from bound C++-style Callable and one call: 1435 cycles; call only: 46 cycles.
One assignment from C-function pointer plus obj, and one call: 151 cycles; call only: 30 cycles.