-
Notifications
You must be signed in to change notification settings - Fork 10
Add Send + Sync bounds to resolve Arc clippy warnings #883
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -306,3 +306,26 @@ impl From<alloc::ffi::NulError> for Error { | |
| Self::NulChar | ||
| } | ||
| } | ||
|
|
||
| // SAFETY: KStatNamed<T> is safe for Send + Sync under the following conditions: | ||
| // | ||
| // 1. Read-only sharing: After creation, the `ksp` pointer is never mutated - only | ||
| // passed to kstat_delete() in Drop. Multiple threads can safely read the same | ||
| // immutable pointer value. | ||
| // | ||
| // 2. Kernel manages concurrency: The kstat framework handles concurrent access to | ||
| // the underlying kernel structures via its own internal mechanisms. | ||
| // | ||
| // 3. Atomic statistics: Individual stats in `vals` use AtomicU64, ensuring each | ||
| // counter update is atomic and thread-safe. | ||
| // | ||
| // 4. Intentional design trade-off: We explicitly do NOT set ks_lock (see struct | ||
| // comment), accepting that different threads may see inconsistent snapshots | ||
| // of the stats as a group, while individual values remain uncorrupted. | ||
| // | ||
| // 5. No shared mutable state: The raw pointer represents a kernel resource with | ||
| // a clear lifecycle (create -> install -> delete) with no Rust-side mutation. | ||
| #[cfg(all(not(feature = "std"), not(test)))] | ||
| unsafe impl<T: KStatProvider> Send for KStatNamed<T> {} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that, currently, this bound is far too broad (i.e., if |
||
| #[cfg(all(not(feature = "std"), not(test)))] | ||
| unsafe impl<T: KStatProvider> Sync for KStatNamed<T> {} | ||
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.
I think this can be more concisely summarised, after applying the other suggested change, as a statement that:
Tmust itself beSend + Syncbecause it is fully visible to any user of thestruct. We meet this through the new type bound onKStatProvider.kspis itself safe to move between threads, sinceKSTAT(9S)imposes no MT constraints on callers.kspis never exposed via a&ref (nor is it used by any methods taking&self), and is only used duringdropas you point out above.