Skip to content

Commit

Permalink
Add Send/Sync to token, needed for LockGuard Send/Sync impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-Janggun committed Oct 23, 2024
1 parent 2287e7a commit 95578bf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lock/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::ops::{Deref, DerefMut};
// TODO: For weak memory, there needs to be a bit more stricter condition. unlock -hb→ lock.
pub unsafe trait RawLock: Default + Send + Sync {
/// Raw lock's token type.
type Token;
type Token: Send + Sync;

/// Acquires the raw lock.
fn lock(&self) -> Self::Token;
Expand Down
3 changes: 3 additions & 0 deletions src/lock/clhlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ struct Node {
#[derive(Debug, Clone)]
pub struct Token(*const CachePadded<Node>);

unsafe impl Send for Token {}
unsafe impl Sync for Token {}

/// CLH lock.
#[derive(Debug)]
pub struct ClhLock {
Expand Down
3 changes: 3 additions & 0 deletions src/lock/mcslock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct Node {
#[derive(Debug, Clone)]
pub struct Token(*mut CachePadded<Node>);

unsafe impl Send for Token {}
unsafe impl Sync for Token {}

/// An MCS lock.
#[derive(Debug)]
pub struct McsLock {
Expand Down
3 changes: 3 additions & 0 deletions src/lock/mcsparkinglock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct Node {
#[derive(Debug, Clone)]
pub struct Token(*mut CachePadded<Node>);

unsafe impl Send for Token {}
unsafe impl Sync for Token {}

/// An MCS parking lock.
#[derive(Debug)]
pub struct McsParkingLock {
Expand Down

0 comments on commit 95578bf

Please sign in to comment.