summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mutex.rs26
-rw-r--r--src/mutex/guard.rs2
-rw-r--r--src/rwlock.rs4
-rw-r--r--src/rwlock/read_guard.rs2
-rw-r--r--src/rwlock/write_guard.rs2
5 files changed, 30 insertions, 6 deletions
diff --git a/src/mutex.rs b/src/mutex.rs
index 59e55a9..cef338e 100644
--- a/src/mutex.rs
+++ b/src/mutex.rs
@@ -52,5 +52,29 @@ pub struct MutexRef<'a, T: ?Sized + 'a, R: RawMutex>(
pub struct MutexGuard<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable + 'key, R: RawMutex> {
mutex: MutexRef<'a, T, R>,
thread_key: Key,
- _phantom2: PhantomData<&'key ()>,
+ _phantom: PhantomData<&'key ()>,
+}
+
+struct MutexLockFuture<'a, T: ?Sized + 'a, R: RawMutex> {
+ mutex: &'a Mutex<T, R>,
+ key: Option<crate::ThreadKey>,
+}
+
+impl<'a, T: ?Sized + 'a, R: RawMutex> std::future::Future for MutexLockFuture<'a, T, R> {
+ type Output = MutexGuard<'a, 'a, T, crate::ThreadKey, R>;
+
+ fn poll(
+ mut self: std::pin::Pin<&mut Self>,
+ cx: &mut std::task::Context<'_>,
+ ) -> std::task::Poll<Self::Output> {
+ match unsafe { self.mutex.try_lock_no_key() } {
+ Some(guard) => std::task::Poll::Ready(unsafe {
+ MutexGuard::new(guard.0, self.key.take().unwrap())
+ }),
+ None => {
+ cx.waker().wake_by_ref();
+ std::task::Poll::Pending
+ }
+ }
+ }
}
diff --git a/src/mutex/guard.rs b/src/mutex/guard.rs
index 69960cf..c7f25e4 100644
--- a/src/mutex/guard.rs
+++ b/src/mutex/guard.rs
@@ -61,7 +61,7 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawMutex> MutexGuard<'a, 'ke
Self {
mutex: MutexRef(mutex, PhantomData),
thread_key,
- _phantom2: PhantomData,
+ _phantom: PhantomData,
}
}
}
diff --git a/src/rwlock.rs b/src/rwlock.rs
index df68fc5..7fb8c7a 100644
--- a/src/rwlock.rs
+++ b/src/rwlock.rs
@@ -89,7 +89,7 @@ pub struct RwLockWriteRef<'a, T: ?Sized, R: RawRwLock>(
pub struct RwLockReadGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLock> {
rwlock: RwLockReadRef<'a, T, R>,
thread_key: Key,
- _phantom1: PhantomData<&'key ()>,
+ _phantom: PhantomData<&'key ()>,
}
/// RAII structure used to release the exclusive write access of a lock when
@@ -102,5 +102,5 @@ pub struct RwLockReadGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLoc
pub struct RwLockWriteGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLock> {
rwlock: RwLockWriteRef<'a, T, R>,
thread_key: Key,
- _phantom1: PhantomData<&'key ()>,
+ _phantom: PhantomData<&'key ()>,
}
diff --git a/src/rwlock/read_guard.rs b/src/rwlock/read_guard.rs
index 1fbbceb..532a6e7 100644
--- a/src/rwlock/read_guard.rs
+++ b/src/rwlock/read_guard.rs
@@ -46,7 +46,7 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock>
Self {
rwlock: RwLockReadRef(rwlock, PhantomData),
thread_key,
- _phantom1: PhantomData,
+ _phantom: PhantomData,
}
}
}
diff --git a/src/rwlock/write_guard.rs b/src/rwlock/write_guard.rs
index 0121140..6549822 100644
--- a/src/rwlock/write_guard.rs
+++ b/src/rwlock/write_guard.rs
@@ -63,7 +63,7 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock>
Self {
rwlock: RwLockWriteRef(rwlock, PhantomData),
thread_key,
- _phantom1: PhantomData,
+ _phantom: PhantomData,
}
}
}