-
Notifications
You must be signed in to change notification settings - Fork 987
Add RwLock to embassy-sync #3932
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
Fixes embassy-rs#1394 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/embassy-rs/embassy/issues/1394?shareId=XXXX-XXXX-XXXX-XXXX).
* Implement `RawRwLock` trait with methods for read and write locking * Implement `RawRwLockImpl` struct with atomic state and waker * Implement `RawRwLockImpl::lock_read`, `RawRwLockImpl::try_lock_read`, and `RawRwLockImpl::unlock_read` methods * Implement `RawRwLockImpl::lock_write`, `RawRwLockImpl::try_lock_write`, and `RawRwLockImpl::unlock_write` methods
…ions in ThreadModeRawRwLock
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.
Thanks for the PR! I have some question specifically around the critical section raw rw lock, which I don't understand how can work in a single executor.
…r rwlock for a simpler approach
…ods, enhancing lock acquisition flexibility
…uards to improve data access flexibility
This still seems open. |
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.
Could you give an example for needing to use the map()? Won't
let g = lock.read().await;
do_stuff(g.deref());
allow you to 'calling methods on the contents of the RwLockReadGuard
without moving out of the guard' as stated in the comment?
To manage the rather complex state of an embedded device I drafted this code:
The many information sections in DISPLAY_STATE can be read by certain "threads" of the firmware and written by others. hence Right now I don't see the necessity of using more than the |
I've just transposed the mutex pattern to RwLock for consistency but I can remove map guard if it is not necessary. |
Thanks a lot |
Yeah, please remove it. If there is a use case for it, it can be added later. |
lgtm other than @lulf 's feedback. please mark as ready for review when done. |
…aning up code for improved readability
Done ! |
In addition, I was wondering if implementing a blocking version (like the blocking mutex) would be useful. I can do it if you'd like. |
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.
thanks!
Fixes #1394
The implementation is very similar to
Mutex