-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix(macOS): Use Mach Precedence Policy for Soft Real-Time Thread Priority and std::chrono::duration Casting Error #5679
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
Conversation
…rity Signed-off-by: Dhruv Patel <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah - this is now a 1000 line PR and its broken a few linting rules. Checkout the CI failed job. Otherwise I approve.
i ran pre-commit to all the files. 😅 |
|
Alot of these changes look correct, I'm confused why they weren't flagged before. I've been noticing for months now that some parts of the linting profile aren't being flagged correctly. It seems like a change in the ament linting rules or something that I don't understand. If you have any ideas, I'd love to hear it. I've looked into it before and didn't come up with anything Edit: So I'd say just fix the few things it flags as wrong and leave the rest. thanks for the service 🫡 |
Signed-off-by: Dhruv Patel <[email protected]>
here we go! 😇 |
|
Just waiting on CI |
|
@idesign0, your PR has failed to build. Please check CI outputs and resolve issues. |
This PR introduces the necessary platform-specific implementation for thread prioritization within
nav2_util::setSoftRealTimePriority()for macOS systems.Context
macOS does not support the standard POSIX real-time scheduling policies (
SCHED_FIFOorSCHED_RR) for user-level threads, which are relied upon in the existing Linux (#else) implementation. When running on macOS, This resulted in a compilation error (e.g., "undeclared identifier") on macOS, completely blocking the build process for the package.Solution
The code is updated within the
#ifdef __APPLE__block to use the native Mach kernel API, which is the correct and most effective method for this platform:THREAD_PRECEDENCE_POLICY, setting theimportanceto the maximum value (63). This achieves the highest available user-space priority, fulfilling the requirement for soft real-time performance on macOS.<mach/error.h>and uses the functionmach_error_string()to provide a human-readable description of thekern_return_terror code if the policy fails to set.Files Changed
nav2_util/src/node_utils.cppFix: std::chrono::duration Casting Error
This resolves a strict type conversion error specific to Clang/libc++ on macOS builds.
Problem:
The
Tree::sleep()function expects astd::chrono::microsecondsduration (orsystem_clock::duration), but the calling code provides a higher-resolutionstd::chrono::nanosecondsduration (time_to_sleep_ns). The macOS compiler rejects this implicit conversion due to potential data loss (truncation).Solution:
Added an explicit
std::chrono::duration_cast<std::chrono::microseconds>()wrapper to explicitly convert the nanosecond duration before passing it totree_->sleep(), resolving the compilation error.Files Changed:
nav2_behavior_tree/include/nav2_behavior_tree/utils/loop_rate.hpp