summaryrefslogtreecommitdiff
path: root/src/mutex.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mutex.rs')
-rw-r--r--src/mutex.rs26
1 files changed, 25 insertions, 1 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
+ }
+ }
+ }
}