Skip to content

FunctionalInterrupt - type tagging & smaller obj size - #9337

Open
mcspr wants to merge 6 commits into
esp8266:masterfrom
mcspr:interrupt-it
Open

mcspr wants to merge 6 commits into
esp8266:masterfrom
mcspr:interrupt-it

Conversation

@mcspr

@mcspr mcspr commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

ref. #5922 for the original .ld snippet
add the missing member function pointer to invoker aka actual func obj
remove everything else that sort-of matches std::function signature. w/ a simple web server app this frees up ~600bytes of IRAM.

function dispatch rewrite inlines interrupt caller operator()(), but the lambda still needs to be in iram. this happens by matching the invoker func signature, which has esp8266::FunctionalInterrupt::Tag in its arguments list. caller may use auto, since the struct does nothing otherwise

// ...
  int foobar = 5;
  attachInterrupt(2, [&](auto) { foobar += 5; }, CHANGE);
// ...

(also choosing to ignore the throw on null func check inside operator()(). at least for now. in case there is a way to shorten the operator method w/o rewriting the header, it would be a nice addition here specifically. barring an option of a whole other lambda functor container&caller class)

SPISlave plus example rewritten to accept pointers, since sample lambdas were not actually utilizing std::function container in any way.

note that scheduled_function & scheduled interrupt sort-of work (?) under the same assumption
but, it has a whole bunch of other issues like malloc/new, constructors and copies being done all at once

mcspr added 6 commits November 6, 2026 19:05
private struct handling limited to one compilation unit

real funcs get pulled whenever attachInterrupt requests std::function overload
weakly linked stubs are used by default
add a note about unsafe execution from isr context
ref. esp8266#5922

still utilize section split, but put both operator and invoker
latter being was omitted for some reason in the original pr

additionally, resolve ambigous overload of base attachInterrupt
in case functor can be converted into a pointer but cannot decide
between std::function<void(void)> and void(*)(void)
note that the same restrictions as w/ free also apply here

specific use-case for right now is detaching interrupt callers
allocating things is a whole other matter

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant