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

[BUILD] Provide LIKELY / UNLIKELY macros #2580

Merged
merged 4 commits into from
Mar 11, 2024

Conversation

marcalff
Copy link
Member

@marcalff marcalff commented Mar 7, 2024

Contributes to #2572

Changes

Please provide a brief description of the changes here.

  • Remove the OPENTELEMETRY_LIKELY_IF macro
    • This macro does not make sense because it includes the if itself, making it unusable for other constructs (for loops, while loops)
  • Provide a OPENTELEMETRY_LIKELY_CONDITION macro
    • To be used instead of OPENTELEMETRY_LIKELY_IF.
    • Only one argument is supported instead of a __VA_ARGS__, to discourage if OPENTELEMETRY_LIKELY_CONDITION (a = foo(), b = bar(), a > b)
    • This macro supports both compiler builtins for gcc and clang, and C++20.
  • Provide a OPENTELEMETRY_UNLIKELY_CONDITION macro
  • Provide a OPENTELEMETRY_LIKELY macro
  • Provide a OPENTELEMETRY_UNLIKELY macro

With this change, likely / unlikely hints can be placed anywhere (for loops, while loops, switch case, etc). These hints are not used only for if conditions.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@marcalff marcalff requested a review from a team March 7, 2024 20:31
Copy link
Member

@owent owent left a comment

Choose a reason for hiding this comment

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

LGTM and thanks.

@esigo esigo merged commit 25738f3 into open-telemetry:main Mar 11, 2024
47 checks passed
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request Mar 12, 2024
[BUILD] Provide LIKELY / UNLIKELY macros (open-telemetry#2580)
@marcalff marcalff deleted the fix_likely branch June 3, 2024 21:06
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.

3 participants