Repository navigation
Conversation
A mutex owner inherits a waiter's priority only at the moment the waiter blocks in tx_mutex_get. _tx_thread_priority_change on a thread that is not ready updated that thread's own priority fields and nothing else, so a thread waiting on a TX_INHERIT mutex could be raised above the owner without the owner following, and a waiter the owner had inherited from could be lowered while the owner kept the old priority. When the thread is suspended on a mutex, _tx_thread_priority_change now calls a new internal function, _tx_mutex_inherit_priority_update, which recomputes the mutex's highest waiting priority, the owner's inherited priority across every mutex it holds, and the owner's priority. The call goes through a new function pointer, _tx_thread_mutex_priority_update, set by tx_mutex_create in the same way as _tx_thread_mutex_release, so the thread services still do not link the mutex services. Applied to common and common_smp. threadx_mutex_inherit_waiter_priority_change_test changes the priorities of two waiters in four steps that raise the owner, lower it to the other waiter, and finally return it to its own priority. Added to both suites. Without the fix it fails with ERROR eclipse-threadx#30 in both; with it, the mutex tests pass in both suites' default_build_coverage configuration, and the changed sources build cleanly under -Wall -Wextra -Werror with TX_NOT_INTERRUPTABLE, TX_MISRA_ENABLE, TX_DISABLE_PREEMPTION_THRESHOLD and event trace.
fdesbiens
self-requested a review
October 16, 2026 13:30
fdesbiens
requested changes
Oct 16, 2026
fdesbiens
left a comment
Contributor
There was a problem hiding this comment.
Hi @howjmay. Thank you for this contribution. Updating inheritance when a waiter’s priority changes addresses a real gap. I left one behavior issue below. Please also add a ready-owner test, report coverage for the modified production code, and retarget the PR to dev.
| #endif | ||
|
|
||
| /* Update the priority inheritance of the mutex owner. */ | ||
| (_tx_thread_mutex_priority_update)(mutex_ptr); |
Contributor
There was a problem hiding this comment.
Could this update be limited to TX_INHERIT mutexes? For a TX_NO_INHERIT mutex with multiple waiters, the helper calls _tx_mutex_prioritize, so changing a waiter’s priority can change FIFO acquisition order. A regression checking that order would help protect this case.
_tx_thread_priority_change called _tx_mutex_inherit_priority_update for a thread waiting on any mutex. For a TX_NO_INHERIT mutex with several waiters, the helper's call to _tx_mutex_prioritize moved the changed waiter to the front of the suspension list, so changing a waiter's priority changed the FIFO order in which the waiters obtain the mutex. The update now runs only when the mutex was created with TX_INHERIT, and the helper's header states that requirement. Applied to common and common_smp. threadx_mutex_inherit_waiter_priority_change_test now also checks: - that three waiters on a TX_NO_INHERIT mutex obtain it in the order they blocked after the last one is raised above the others. Without the fix it fails with ERROR eclipse-threadx#62 in both suites. - a ready owner, moved 10, 15, 8 and back to 15 by changes to its waiter's priority, and that the owner runs before the call returns when the caller is below the owner's new priority. - an owner holding two TX_INHERIT mutexes and one TX_NO_INHERIT mutex, including a step that leaves the owner's priority unchanged. - two cases set up by hand: a TX_MUTEX_SUSP thread whose cleanup has already been cleared, and the helper run on a mutex with no waiters left. The test passes in every tx and smp build configuration. Merged coverage of the changed lines is 100% of lines and branches, except the TX_MISRA_ENABLE retry loop around _tx_mutex_prioritize, which cannot iterate because _tx_misra_status_get always returns TX_SUCCESS. The same loops in tx_mutex_put.c are also half covered.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A mutex owner inherits a waiter's priority only at the moment the waiter blocks in tx_mutex_get. _tx_thread_priority_change on a thread that is not ready updated that thread's own priority fields and nothing else, so a thread waiting on a TX_INHERIT mutex could be raised above the owner without the owner following, and a waiter the owner had inherited from could be lowered while the owner kept the old priority.
When the thread is suspended on a mutex, _tx_thread_priority_change now calls a new internal function, _tx_mutex_inherit_priority_update, which recomputes the mutex's highest waiting priority, the owner's inherited priority across every mutex it holds, and the owner's priority. The call goes through a new function pointer, _tx_thread_mutex_priority_update, set by tx_mutex_create in the same way as _tx_thread_mutex_release, so the thread services still do not link the mutex services. Applied to common and common_smp.
threadx_mutex_inherit_waiter_priority_change_test changes the priorities of two waiters in four steps that raise the owner, lower it to the other waiter, and finally return it to its own priority. Added to both suites. Without the fix it fails with ERROR #30 in both; with it, the mutex tests pass in both suites' default_build_coverage configuration, and the changed sources build cleanly under -Wall -Wextra -Werror with TX_NOT_INTERRUPTABLE, TX_MISRA_ENABLE, TX_DISABLE_PREEMPTION_THRESHOLD and event trace.
PR checklist