-
-
Notifications
You must be signed in to change notification settings - Fork 26
Add homemade rwlock for no_std #140
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
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.
Pull Request Overview
This PR introduces a custom spinlock-based reader-writer lock implementation for no_std environments, replacing the parking_lot dependency when the std feature is not enabled.
- Implements
RawSpinRwLockusing atomic operations and compare-exchange primitives - Adds conditional compilation to use the custom rwlock in no_std mode while keeping parking_lot for std builds
- Updates Cargo.toml dependencies to make parking_lot optional and adds lock_api
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/sync.rs | New module implementing spinlock-based reader-writer lock with comprehensive tests |
| src/lib.rs | Conditionally includes sync module for no_std builds |
| src/config.rs | Imports custom RwLock for no_std, parking_lot for std builds |
| Cargo.toml | Makes parking_lot optional, adds lock_api dependency, updates std feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| #[inline] | ||
| fn try_lock_shared(&self) -> bool { | ||
| let mut state = self.state.load(Ordering::Relaxed); |
Copilot
AI
Oct 9, 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.
Using Relaxed ordering for the initial load may miss recent state changes from other threads. Consider using Acquire ordering to ensure visibility of writes from unlock operations.
| let mut state = self.state.load(Ordering::Relaxed); | |
| let mut state = self.state.load(Ordering::Acquire); |
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.
That's not correct, Ordering::Acquire is used compare_exchange_weak
Co-authored-by: Copilot <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #140 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 11 12 +1
Lines 489 661 +172
==========================================
+ Hits 489 661 +172 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
78fc66d to
4a6fe75
Compare
4a6fe75 to
28875d8
Compare
Inspired by #139