forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
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
pthread_cond_wait: Use atomic_t to protect the waiter count #339
Merged
Conversation
This file contains 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
atomic_read is missing from the nuttx headers, it is added later in upstream. !! REMOVE THIS COMMIT WHEN REBASING WITH UPSTREAM !!
jlaitine
approved these changes
Jan 17, 2025
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.
Neat!
Because sem_getvalue modifies errno.
Because sem_getvalue modifies errno.
sem_getvalue returns ERROR and sets errno if it fails, we don't want to return OK in this case, we want to return the non-negated error number.
sem_getvalue returns ERROR and sets errno if it fails, we don't want to return OK in this case, we want to return the non-negated error number.
The load/compare and RMW to wait_count need protection. Using atomic operations should resolve both issues. NOTE: The assumption that the user will call pthread_cond_signal / pthread_cond_broadcast with the mutex given to pthread_cond_wait held is simply not true. It MAY hold it, but it is not forced. Thus, using the user space lock for protecting the wait counter as well is not valid! The pthread_cond_signal() or pthread_cond_broadcast() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() have associated with the condition variable during their waits; however, if predictable scheduling behaviour is required, then that mutex is locked by the thread calling pthread_cond_signal() or pthread_cond_broadcast(). [1] https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_signal.html
LGTM; just wondering whether the i2c and fb driver changes are here on purpose (fb we are not even using afaik) ? |
jlaitine
approved these changes
Jan 20, 2025
They can be dropped / are not tightly related. Just took everything that was changed in the upstream PR. |
it is ok to keep those! |
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.
pthread_cond_wait: Use atomic_t to protect the waiter count
From upstream (hopefully)