From b3fdc2cd2172cf946c79e255d4248e135c0d9669 Mon Sep 17 00:00:00 2001 From: Mica White Date: Tue, 12 Mar 2024 14:33:02 -0400 Subject: Name change --- src/mutex.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/mutex.rs') 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, + key: Option, +} + +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 { + 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 + } + } + } } -- cgit v1.2.3