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

Add aws_min_non_0_64() #983

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add aws_min_non_0_64() #983

wants to merge 2 commits into from

Conversation

sbSteveK
Copy link
Contributor

helper function aws_min_non_0_64 used in multiple places moved to common.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

Codecov Report

Base: 80.87% // Head: 80.78% // Decreases project coverage by -0.09% ⚠️

Coverage data is based on head (942eea2) compared to base (50695e9).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #983      +/-   ##
==========================================
- Coverage   80.87%   80.78%   -0.09%     
==========================================
  Files          53       53              
  Lines        5678     5678              
==========================================
- Hits         4592     4587       -5     
- Misses       1086     1091       +5     
Impacted Files Coverage Δ
source/bus.c 89.80% <0.00%> (-2.43%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -186,6 +186,7 @@ AWS_STATIC_IMPL uint32_t aws_max_u32(uint32_t a, uint32_t b);
AWS_STATIC_IMPL int32_t aws_min_i32(int32_t a, int32_t b);
AWS_STATIC_IMPL int32_t aws_max_i32(int32_t a, int32_t b);
AWS_STATIC_IMPL uint64_t aws_min_u64(uint64_t a, uint64_t b);
AWS_STATIC_IMPL uint64_t aws_min_non_0_u64(uint64_t a, uint64_t b);
Copy link
Contributor

@graebm graebm Feb 16, 2023

Choose a reason for hiding this comment

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

something like clamp() seems more generically useful?

uint64_t aws_clamp_u64(uint64_t val, uint64_t low, uint64_t high);

using it would look like:

next_service_time = aws_clamp_u64(operation_processing_time, 1, next_service_time);

which is equivalent to the proposed:

next_service_time = aws_min_non_0_64(operation_processing_time, next_service_time);

Copy link
Contributor

@bretambrose bretambrose Feb 16, 2023

Choose a reason for hiding this comment

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

They're not equivalent. Think of 0 as NULL/none

Copy link
Contributor

Choose a reason for hiding this comment

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

For that matter, maybe we need a serious name change that reflects that null/none property.

Copy link
Contributor

Choose a reason for hiding this comment

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

This all comes from the mqtt5 client architecture for composing next service time calculations. 0 means no-affect, non-zero means a time constraint. We want the smallest non-zero time constraint as our next scheduled time.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this should just stay an MQTT5 helper function, it's kinda weird as a generic math operation.
Looking at this header file, which is just a function name with no docs, assumed it meant "min, but higher than 0".

Copy link
Contributor

Choose a reason for hiding this comment

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

We're using it in secure tunneling too now.

Copy link
Contributor

Choose a reason for hiding this comment

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

aws_min_u64_nullable might be closer to a name improvement.

Copy link
Contributor

@graebm graebm Feb 16, 2023

Choose a reason for hiding this comment

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

whatever we name it, add docs to the header file explaining what it does

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.

4 participants