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

feat(maitake): add WaitQueue #191

Merged
merged 25 commits into from
Jun 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
don't use spinlocks in loom tests
this fixes test failures due to unbounded branches

Signed-off-by: Eliza Weisman <[email protected]>
hawkw committed Jun 4, 2022

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit f0ec8fdebe7f2f401cf08ea094e81ddefb996085
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion maitake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ git = "https://github.com/tokio-rs/tracing"
futures-util = "0.3"

[target.'cfg(loom)'.dev-dependencies]
loom = { version = "0.5.5", features = ["futures"] }
loom = { version = "0.5.5", features = ["futures", "checkpoint"] }
tracing_01 = { package = "tracing", version = "0.1", default_features = false }
tracing_subscriber_03 = { package = "tracing-subscriber", version = "0.3.11", features = ["fmt"] }

39 changes: 37 additions & 2 deletions maitake/src/loom.rs
Original file line number Diff line number Diff line change
@@ -3,9 +3,42 @@ pub(crate) use self::inner::*;

#[cfg(loom)]
mod inner {
#![allow(dead_code)]

#[cfg(feature = "alloc")]
pub use loom::alloc;
pub use loom::{cell, future, hint, model, sync, thread};
pub(crate) use loom::alloc;
pub(crate) use loom::{cell, future, hint, model, thread};

pub(crate) mod sync {
pub(crate) use loom::sync::*;

pub(crate) mod spin {
pub(crate) use loom::sync::MutexGuard;

/// Mock version of mycelium's spinlock, but using
/// `loom::sync::Mutex`. The API is slightly different, since the
/// mycelium mutex does not support poisoning.
#[derive(Debug)]
pub(crate) struct Mutex<T>(loom::sync::Mutex<T>);

impl<T> Mutex<T> {
#[track_caller]
pub(crate) fn new(t: T) -> Self {
Self(loom::sync::Mutex::new(t))
}

#[track_caller]
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
self.0.try_lock().ok()
}

#[track_caller]
pub fn lock(&self) -> MutexGuard<'_, T> {
self.0.lock().expect("loom mutex will never poison")
}
}
}
}
}

#[cfg(not(loom))]
@@ -15,6 +48,8 @@ mod inner {
#[cfg(feature = "alloc")]
pub use alloc::sync::*;
pub use core::sync::*;

pub use mycelium_util::sync::spin;
}

pub(crate) use core::sync::atomic;
7 changes: 5 additions & 2 deletions maitake/src/wait/queue.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::{
loom::{
cell::UnsafeCell,
sync::atomic::{
sync::{
spin::Mutex,
atomic::{
AtomicUsize,
Ordering::*,
},
}
},
util,
wait::{self, WaitResult},
@@ -22,7 +25,7 @@ use core::{
mem,
};
use mycelium_bitfield::{FromBits, bitfield};
use mycelium_util::sync::{spin::Mutex, CachePadded};
use mycelium_util::sync::CachePadded;
#[cfg(test)]
use mycelium_util::fmt;
use pin_project::{pin_project, pinned_drop};