Skip to content
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

Iox 1640 create polymorphic singleton abstraction #1656

Conversation

MatthiasKillat
Copy link
Contributor

@MatthiasKillat MatthiasKillat commented Sep 20, 2022

Pre-Review Checklist for the PR Author

  1. Code follows the coding style of CONTRIBUTING.md
  2. Tests follow the best practice for testing
  3. Changelog updated in the unreleased section including API breaking changes
  4. Branch follows the naming format (iox-123-this-is-a-branch)
  5. Commits messages are according to this guideline
    • Commit messages have the issue ID (iox-#123 commit text)
    • Commit messages are signed (git commit -s)
    • Commit author matches Eclipse Contributor Agreement (and ECA is signed)
  6. Update the PR title
    • Follow the same conventions as for commit messages
    • Link to the relevant issue
  7. Relevant issues are linked
  8. Add sensible notes for the reviewer
  9. All checks have passed (except task-list-completed)
  10. All touched (C/C++) source code files from iceoryx_hoofs are added to ./clang-tidy-diff-scans.txt
  11. Assign PR to reviewer

Notes for Reviewer

refer to https://github.com/eclipse-iceoryx/iceoryx/pull/1656/files#diff-b342f851e544aab4457e99291a6b66baad23e941cfb95dbc4454bf08669dc356 for explanation of the functionality

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Code according to our coding style and naming conventions
  • Unit tests have been written for new behavior
  • Public API changes are documented via doxygen
  • Copyright owner are updated in the changed files
  • All touched (C/C++) source code files from iceoryx_hoofs have been added to ./clang-tidy-diff-scans.txt
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Sep 20, 2022

I need to port the clang format CI fix from the other PR to this one. The other PR will likely not be merged soon, but @elBoberido proposed how to build a singleton manager on top as well to solve the singleton destruction order problem.

This will become important for posh and hopefully be a useful building block.

The current PR is for error handling and logging.

Copy link
Contributor

@elfenpiff elfenpiff left a comment

Choose a reason for hiding this comment

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

Please

  • use include guards instead of pragma once
  • add the copyright header
  • move implementation into inl file
  • use noexcept on every method
  • do not use std::cerr, use Logger instead
  • do not use std::terminate, use cxx::Ensures instead

@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Sep 21, 2022

@elfenpiff The restructuring will be done.

However, we should not have the default implementation depend on logger or later error handler. We could have empty default behavior instead of terminate, the hook is supposed to be set somehow by the concrete logger or error handler.

Some methods can be noexcept, but not all I think. Need to evaluate generics. I only will add it where we can provide a no-throw guarantee.

@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Merging #1656 (b35cb02) into master (5f4dd12) will increase coverage by 0.07%.
The diff coverage is 92.64%.

❗ Current head b35cb02 differs from pull request most recent head fcf639d. Consider uploading reports for the commit fcf639d to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1656      +/-   ##
==========================================
+ Coverage   75.42%   75.49%   +0.07%     
==========================================
  Files         377      379       +2     
  Lines       14619    14693      +74     
  Branches     2084     2098      +14     
==========================================
+ Hits        11026    11093      +67     
  Misses       2961     2961              
- Partials      632      639       +7     
Flag Coverage Δ
unittests 75.16% <92.64%> (+0.07%) ⬆️
unittests_timing 15.28% <23.52%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...fs/internal/design_pattern/polymorphic_handler.inl 91.89% <91.89%> (ø)
.../internal/design_pattern/static_lifetime_guard.inl 93.54% <93.54%> (ø)
...sh/include/iceoryx_posh/internal/popo/wait_set.inl 91.47% <0.00%> (-1.22%) ⬇️

@mossmaurice mossmaurice added the enhancement New feature label Sep 21, 2022
@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Sep 21, 2022

Refactored and added some commits of @dkroenke to update clang-format.

@MatthiasKillat MatthiasKillat force-pushed the iox-1640-create-polymorphic-singleton-abstraction branch 4 times, most recently from c57627f to 7aab2d3 Compare September 21, 2022 12:24
@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Sep 22, 2022

I made all methods noexcept, even if formally no nothrow guarantee can be given for almost all of them.

I am still not sure how Axivion treats this. I think if it cannot prove that everything is noxexcept in the implementation it does not care (function can be noexcept but does not have to).

Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

Just a quick first review

@MatthiasKillat MatthiasKillat force-pushed the iox-1640-create-polymorphic-singleton-abstraction branch 8 times, most recently from 01574c5 to 2b80ab6 Compare October 21, 2022 21:19
@MatthiasKillat
Copy link
Contributor Author

MatthiasKillat commented Oct 24, 2022

@elBoberido I adressed the following issues.

  1. Use of mutex - not required anymore but it will block during concurrent instance construction (only one call is allowed to access the memory to construct), there is no way around it with limited memory to construct the instance (but it will always return with fair scheduling, as it would with mutex)
  2. ensure the lifetime of the handlers to be set by enforcing the use of a StaticLifetimeGuard
  3. The StaticLifetimeGuard essentially generalizes/adapts the nifty counter pattern but provides arguably better encapsulation and easier usage

This introduces complexity in the implementation but I think they are useful buildings blocks for recurring problems. I placed them in design_patterns (because they are design_patterns) but I am not very attached to this name (could be a building block, whatever).

elBoberido
elBoberido previously approved these changes Jan 30, 2023
@MatthiasKillat MatthiasKillat force-pushed the iox-1640-create-polymorphic-singleton-abstraction branch 5 times, most recently from a71a290 to ed0b134 Compare January 31, 2023 10:11
@MatthiasKillat MatthiasKillat force-pushed the iox-1640-create-polymorphic-singleton-abstraction branch from ed0b134 to b35cb02 Compare January 31, 2023 11:26
doc/design/polymorphic_handler.md Outdated Show resolved Hide resolved
doc/design/polymorphic_handler.md Outdated Show resolved Hide resolved
doc/design/polymorphic_handler.md Outdated Show resolved Hide resolved
doc/design/polymorphic_handler.md Outdated Show resolved Hide resolved
elBoberido
elBoberido previously approved these changes Jan 31, 2023
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

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

I think this is now in good condition as far as the functionality is concerned but I'm a bit skeptical about the API. Unfortunately I don't have a better alternative.

@MatthiasKillat
Copy link
Contributor Author

@elBoberido I am not perfectly happy with the API either, but probably in other ways than you. The guards are good internally but using them in the API limits functionality in ways I did not want initially (partly related to the bool return change` and more.

Nevertheless it solves a problem in a useful way and we can build on that, e.g. I will for error handler exchange.

@MatthiasKillat MatthiasKillat force-pushed the iox-1640-create-polymorphic-singleton-abstraction branch from a4f42dc to 0fba4ac Compare January 31, 2023 13:54
@MatthiasKillat MatthiasKillat force-pushed the iox-1640-create-polymorphic-singleton-abstraction branch from 0fba4ac to 4c259b9 Compare January 31, 2023 14:02
elBoberido
elBoberido previously approved these changes Jan 31, 2023
@@ -39,7 +38,8 @@ struct DefaultHooks
/// @brief called if the polymorphic handler is set or reset after finalize
/// @param currentInstance the current instance of the handler singleton
/// @param newInstance the instance of the handler singleton to be set
static void onSetAfterFinalize(Interface& currentInstance, Interface& newInstance) noexcept;
/// @note calls terminate and does not return
[[noreturn]] static void onSetAfterFinalize(Interface& currentInstance, Interface& newInstance) noexcept;
Copy link
Member

Choose a reason for hiding this comment

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

I guess this does not restrict other hooks to define a non-noreturn method?

Copy link
Contributor Author

@MatthiasKillat MatthiasKillat Jan 31, 2023

Choose a reason for hiding this comment

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

No it does not and should not. It is not mandatory for any hook. It is just plugged in as a template argument type ...

However, it is a guarantee the DefaultHooks are able to give and so they should. Can remove it, but would advise not to. This allows optimization and communicates intent. And is portable in C++11.

@MatthiasKillat MatthiasKillat merged commit d23cab5 into eclipse-iceoryx:master Jan 31, 2023
@MatthiasKillat MatthiasKillat deleted the iox-1640-create-polymorphic-singleton-abstraction branch January 31, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create exchangeable singleton abstraction
5 participants