Skip to content

Commit

Permalink
refactor: switch to async-mutex for Mutex implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jun 26, 2020
1 parent 43de933 commit 18dffe8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 301 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Expand Up @@ -48,6 +48,7 @@ std = [
"slab",
"wasm-bindgen-futures",
"futures-channel",
"async-mutex",
]
alloc = [
"futures-core/alloc",
Expand All @@ -58,6 +59,7 @@ tokio02 = ["smol/tokio02"]
[dependencies]
async-attributes = { version = "1.1.1", optional = true }
async-task = { version = "3.0.0", optional = true }
async-mutex = { version = "1.1.3", optional = true }
crossbeam-utils = { version = "0.7.2", optional = true }
futures-core = { version = "0.3.4", optional = true, default-features = false }
futures-io = { version = "0.3.4", optional = true }
Expand All @@ -75,7 +77,7 @@ futures-timer = { version = "3.0.2", optional = true }
surf = { version = "1.0.3", optional = true }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
smol = { version = "0.1.14", optional = true }
smol = { version = "0.1.17", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
futures-timer = { version = "3.0.2", optional = true, features = ["wasm-bindgen"] }
Expand Down
8 changes: 4 additions & 4 deletions src/sync/condvar.rs
Expand Up @@ -2,7 +2,7 @@ use std::fmt;
use std::pin::Pin;
use std::time::Duration;

use super::mutex::{guard_lock, MutexGuard};
use super::MutexGuard;
use crate::future::{timeout, Future};
use crate::sync::WakerSet;
use crate::task::{Context, Poll};
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Condvar {
/// ```
#[allow(clippy::needless_lifetimes)]
pub async fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
let mutex = guard_lock(&guard);
let mutex = MutexGuard::source(&guard);

self.await_notify(guard).await;

Expand Down Expand Up @@ -228,7 +228,7 @@ impl Condvar {
guard: MutexGuard<'a, T>,
dur: Duration,
) -> (MutexGuard<'a, T>, WaitTimeoutResult) {
let mutex = guard_lock(&guard);
let mutex = MutexGuard::source(&guard);
match timeout(dur, self.wait(guard)).await {
Ok(guard) => (guard, WaitTimeoutResult(false)),
Err(_) => (mutex.lock().await, WaitTimeoutResult(true)),
Expand Down Expand Up @@ -281,7 +281,7 @@ impl Condvar {
where
F: FnMut(&mut T) -> bool,
{
let mutex = guard_lock(&guard);
let mutex = MutexGuard::source(&guard);
match timeout(dur, self.wait_until(guard, condition)).await {
Ok(guard) => (guard, WaitTimeoutResult(false)),
Err(_) => (mutex.lock().await, WaitTimeoutResult(true)),
Expand Down
5 changes: 3 additions & 2 deletions src/sync/mod.rs
Expand Up @@ -176,10 +176,11 @@
#[doc(inline)]
pub use std::sync::{Arc, Weak};

pub use mutex::{Mutex, MutexGuard};
#[doc(inline)]
pub use async_mutex::{Mutex, MutexGuard};

pub use rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};

mod mutex;
mod rwlock;

cfg_unstable! {
Expand Down
294 changes: 0 additions & 294 deletions src/sync/mutex.rs

This file was deleted.

0 comments on commit 18dffe8

Please sign in to comment.