Skip to content
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

Fix unsound lock guard: Remove Send and Sync autotraits from the lock guard #8

Merged
merged 1 commit into from Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib.rs
Expand Up @@ -51,6 +51,7 @@ use core::cell::UnsafeCell;
use core::fmt;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::{AtomicBool, Ordering};
use core::marker::PhantomData;

/// A light-weight lock guarded by an atomic boolean.
///
Expand Down Expand Up @@ -167,6 +168,7 @@ impl<T> TryLock<T> {
Some(Locked {
lock: self,
order: unlock_order,
_p: PhantomData,
})
} else {
None
Expand Down Expand Up @@ -224,6 +226,8 @@ impl<T: fmt::Debug> fmt::Debug for TryLock<T> {
pub struct Locked<'a, T: 'a> {
lock: &'a TryLock<T>,
order: Ordering,
/// Suppresses Send and Sync autotraits for `struct Locked`.
_p: PhantomData<*mut T>,
}

impl<'a, T> Deref for Locked<'a, T> {
Expand Down