Initialized the suspend status before the non-interruptable suspend in tx_thread_sleep, so a sleep no longer returns a stale error left over from an earlier timed-out suspension - #725
Merged
Conversation
…n tx_thread_sleep, so a sleep no longer returns a stale error left over from an earlier timed-out suspension When TX_NOT_INTERRUPTABLE is defined, _tx_thread_sleep did not set tx_thread_suspend_status to TX_SUCCESS before calling _tx_thread_system_ni_suspend. The interruptable path always did. Nothing else writes that field on behalf of a sleeping thread: _tx_thread_timeout resumes a TX_SLEEP thread directly and there is no suspend cleanup routine for sleep. The value therefore survived from whatever suspension the thread performed last, and tx_thread_sleep returned it. A tx_semaphore_get that timed out with TX_NO_INSTANCE would be followed by a tx_thread_sleep that also returned TX_NO_INSTANCE after sleeping correctly. The same change is applied to the SMP copy, which is identical. Assisted-by: Copilot (Opus 5) <noreply@github.com>
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.
Fixes #433.
When
TX_NOT_INTERRUPTABLEis defined,_tx_thread_sleep()did not settx_thread_suspend_statustoTX_SUCCESSbefore calling_tx_thread_system_ni_suspend(). The interruptable path has always done so.Nothing else writes that field on behalf of a sleeping thread:
_tx_thread_timeout()resumes aTX_SLEEPthread directly, and unlike the semaphore, queue, mutex and event flags paths there is no suspend cleanup routine for sleep that would set a status. The field therefore kept whatever value the thread's previous suspension left in it, andtx_thread_sleep()returned that value. Atx_semaphore_get()that timed out withTX_NO_INSTANCEwas followed by atx_thread_sleep()that slept correctly but also returnedTX_NO_INSTANCE.This is the fix @billlamiework proposed in the issue thread. The same change is applied to
common_smp/src/tx_thread_sleep.c, which is byte-identical to the non-SMP copy.Validation:
test/tx98/98 andtest/smp114/114 pass. Neither suite has aTX_NOT_INTERRUPTABLEconfiguration, so both files were additionally compiled with-DTX_NOT_INTERRUPTABLEto confirm the changed path builds.