Skip to content

Callback extension and optimisation #12036

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

Merged
merged 3 commits into from
Mar 27, 2020
Merged

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Dec 5, 2019

Summary of changes

Extend Callback, and optimise it.

Impact of changes

  • Optimise clearing by adding nullptr overload.
  • Optimise clearing by not clearing storage - increases code size of comparison, but that is extremely rare.
  • Reduce ROM used by trivial functors - share copy/destroy code.
  • Config option to force trivial functors - major ROM saving by eliminating the "operations" table.
  • Config option to eliminate comparison altogether - minor ROM saving by eliminating zero padding.
  • Conform more to std::function API.
  • Force trivial functors by default to get major ROM saving. (now in Callback: Trivial default #12761)

Migration actions required

  • The added nullptr overload means Callback(NULL) or Callback(0) will no longer work; users must use Callback(nullptr) or Callback().
  • If application code uses Callback with a non-trivial functor, they will get a compilation error directing them to turn on platform.callback-nontrivial.

Documentation


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[X] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Reviewers

@pan-


@kjbracey
Copy link
Contributor Author

kjbracey commented Dec 5, 2019

This PR is based on and includes #12035, which deals with the breaking changes. Last 3 commits are the new content.

@ciarmcom ciarmcom requested review from pan- and a team December 5, 2019 16:00
@ciarmcom
Copy link
Member

ciarmcom commented Dec 5, 2019

@kjbracey-arm, thank you for your changes.
@pan- @ARMmbed/mbed-os-core @ARMmbed/mbed-os-wan @ARMmbed/mbed-os-storage @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-test @ARMmbed/mbed-os-maintainers please review.

kjbracey added a commit to kjbracey/mbed-os-5-docs that referenced this pull request Dec 9, 2019
Adjust wording to talk of Callback's being "empty", which is clearer
than "null", and avoids thought of `NULL`. Add explicit note about using
`nullptr` to reset.

Preparation for ARMmbed/mbed-os#12036 - can be
merged now as adjustments are valid for existing code.
kjbracey added a commit to kjbracey/mbed-os-5-docs that referenced this pull request Dec 9, 2019
@kjbracey kjbracey force-pushed the callback_fiddle branch 3 times, most recently from c0d55f0 to 5e12858 Compare December 10, 2019 08:54
@kjbracey
Copy link
Contributor Author

I've posted a query about the GCC failure I saw working on this: https://answers.launchpad.net/gcc-arm-embedded/+question/686870

Although the failure has now apparently gone away since removing the full memset of storage, so I'll be removing the workaround of doing memcpy into storage rather than placement-new.

@kjbracey kjbracey force-pushed the callback_fiddle branch 2 times, most recently from 47677c5 to 6adc0a0 Compare December 11, 2019 13:41
@adbridge adbridge requested a review from bulislaw December 17, 2019 16:53
@adbridge
Copy link
Contributor

@kjbracey-arm looks like this also needs a rebase now ...

@adbridge
Copy link
Contributor

adbridge commented Jan 6, 2020

@kjbracey-arm looks like this also needs a rebase now ...

@kjbracey-arm bump....

@0Grit
Copy link

0Grit commented Jan 6, 2020

@AGlass0fMilk please review

@kjbracey kjbracey force-pushed the callback_fiddle branch 2 times, most recently from 623b71d to 587ebc5 Compare March 11, 2020 09:17
@mergify mergify bot added needs: work and removed needs: CI labels Mar 11, 2020
* Optimise clearing by adding `nullptr` overload. This overload means
  `Callback(NULL)` or `Callback(0)` will no longer work; users must
  use `Callback(nullptr)` or `Callback()`.
* Optimise clearing by not clearing storage - increases code size of
  comparison, but that is extremely rare.
* Reduce ROM used by trivial functors - share copy/destroy code.
* Config option to force trivial functors - major ROM saving by
  eliminating the "operations" table.
* Config option to eliminate comparison altogether - minor ROM saving by
  eliminating zero padding.
* Conform more to `std::function` API.
@kjbracey
Copy link
Contributor Author

Fixed up again - had pushed an incorrect version.

Also fixed some problems I was having with breaking optimisation of the "trivial" mode. Long comment with links to explanations included.

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 24, 2020

CI restarted

@mbed-ci
Copy link

mbed-ci commented Mar 24, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 9
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 25, 2020

@ARMmbed/mbed-os-core @bulislaw Please review

@@ -352,13 +352,15 @@ class NetworkInterface: public DNS {
*/
void add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);

#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
/** Remove event listener from interface.
*
* Remove previously added callback from the handler list.
*
* @param status_cb The callback to unregister.
*/
void remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to mention in doxygen that this function is not available if the callback_comparable flag is false, it may be not obvious if user looks at the doxygen and handbook only.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand all of this C++ magic, but I trust Vincent's review :) The rest looks generally ok.

@adbridge adbridge merged commit 009ff7a into ARMmbed:master Mar 27, 2020
iriark01 added a commit to ARMmbed/mbed-os-5-docs that referenced this pull request May 15, 2020
* Add docs for Callback config

Documentation for changes in ARMmbed/mbed-os#12036

* "left set to false" -> "set to false"

Make more ambiguous about default, as there's currently a pending change.

Co-Authored-By: Irit Arkin <[email protected]>

Co-authored-by: Irit Arkin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants