1extern crate alloc;
8use super::semaphore;
9use crate::sync_types;
10use core::ptr;
11use core::{convert, future, marker, ops, pin, task};
12
13#[derive(Clone, Copy, Debug)]
15pub enum AsyncRwLockError {
16 StaleRwLock,
19
20 MemoryAllocationFailure,
22
23 Internal,
25}
26
27impl convert::From<semaphore::AsyncSemaphoreError> for AsyncRwLockError {
28 fn from(value: semaphore::AsyncSemaphoreError) -> Self {
29 match value {
30 semaphore::AsyncSemaphoreError::RequestExceedsSemaphoreCapacity => AsyncRwLockError::Internal,
31 semaphore::AsyncSemaphoreError::StaleSemaphore => AsyncRwLockError::StaleRwLock,
32 semaphore::AsyncSemaphoreError::MemoryAllocationFailure => AsyncRwLockError::MemoryAllocationFailure,
33 semaphore::AsyncSemaphoreError::Internal => AsyncRwLockError::Internal,
34 }
35 }
36}
37
38pub struct AsyncRwLock<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync> {
58 sem: semaphore::AsyncSemaphore<ST, T>,
59}
60
61impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync> AsyncRwLock<ST, T> {
62 pub fn new(data: T) -> Self {
72 Self {
73 sem: semaphore::AsyncSemaphore::new_with_no_capacity(data),
74 }
75 }
76
77 pub fn read<'a, LP: 'a + sync_types::SyncRcPtr<Self>, LR: 'a + sync_types::SyncRcPtrRef<'a, Self, LP>>(
95 this: &LR,
96 ) -> Result<AsyncRwLockReadFuture<ST, T, LP>, AsyncRwLockError>
97 where
98 Self: 'a,
99 {
100 let this_sem = sync_types::SyncRcPtrRefForInner::<'_, _, _, _, AsyncRwLockIndexInnerSemTag>::new(this);
101 let sem_trivial_lease_fut = semaphore::AsyncSemaphore::acquire_leases(&this_sem, 0)?;
102 Ok(AsyncRwLockReadFuture { sem_trivial_lease_fut })
103 }
104
105 pub fn write<'a, LP: 'a + sync_types::SyncRcPtr<Self>, LR: 'a + sync_types::SyncRcPtrRef<'a, Self, LP>>(
123 this: &LR,
124 ) -> Result<AsyncRwLockWriteFuture<ST, T, LP>, AsyncRwLockError>
125 where
126 Self: 'a,
127 {
128 let this_sem = sync_types::SyncRcPtrRefForInner::<'_, _, _, _, AsyncRwLockIndexInnerSemTag>::new(this);
129 let sem_exclusive_all_fut = semaphore::AsyncSemaphore::acquire_exclusive_all(&this_sem)?;
130 Ok(AsyncRwLockWriteFuture { sem_exclusive_all_fut })
131 }
132
133 pub fn try_read<'a, LP: 'a + sync_types::SyncRcPtr<Self>, LR: 'a + sync_types::SyncRcPtrRef<'a, Self, LP>>(
139 this: &LR,
140 ) -> Option<AsyncRwLockReadGuard<ST, T, LP>>
141 where
142 Self: 'a,
143 {
144 let this_sem = sync_types::SyncRcPtrRefForInner::<'_, _, _, _, AsyncRwLockIndexInnerSemTag>::new(this);
145 semaphore::AsyncSemaphore::try_acquire_leases(&this_sem, 0)
146 .unwrap()
147 .map(|sem_trivial_lease_guard| AsyncRwLockReadGuard {
148 sem_trivial_lease_guard,
149 })
150 }
151
152 pub fn try_write<'a, LP: 'a + sync_types::SyncRcPtr<Self>, LR: 'a + sync_types::SyncRcPtrRef<'a, Self, LP>>(
158 this: &LR,
159 ) -> Option<AsyncRwLockWriteGuard<ST, T, LP>>
160 where
161 Self: 'a,
162 {
163 let this_sem = sync_types::SyncRcPtrRefForInner::<'_, _, _, _, AsyncRwLockIndexInnerSemTag>::new(this);
164 semaphore::AsyncSemaphore::try_acquire_exclusive_all(&this_sem).map(|sem_exclusive_all_guard| {
165 AsyncRwLockWriteGuard {
166 sem_exclusive_all_guard,
167 }
168 })
169 }
170}
171
172struct AsyncRwLockIndexInnerSemTag;
179
180impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync> sync_types::DerefInnerByTag<AsyncRwLockIndexInnerSemTag>
181 for AsyncRwLock<ST, T>
182{
183 crate::impl_deref_inner_by_tag!(sem, semaphore::AsyncSemaphore<ST, T>);
184}
185
186pub struct AsyncRwLockReadFuture<
198 ST: sync_types::SyncTypes,
199 T: marker::Send + marker::Sync,
200 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>,
201> {
202 sem_trivial_lease_fut: semaphore::AsyncSemaphoreLeasesFuture<
203 ST,
204 T,
205 sync_types::SyncRcPtrForInner<AsyncRwLock<ST, T>, LP, AsyncRwLockIndexInnerSemTag>,
206 >,
207}
208
209impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
210 AsyncRwLockReadFuture<ST, T, LP>
211{
212 pub fn get_rwlock(&self) -> Option<LP> {
217 self.sem_trivial_lease_fut
218 .get_semaphore()
219 .map(|sem| sem.into_container())
220 }
221}
222
223impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
224 marker::Unpin for AsyncRwLockReadFuture<ST, T, LP>
225{
226}
227
228impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
229 future::Future for AsyncRwLockReadFuture<ST, T, LP>
230{
231 type Output = Result<AsyncRwLockReadGuard<ST, T, LP>, AsyncRwLockError>;
232
233 fn poll(self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
241 future::Future::poll(pin::Pin::new(&mut self.get_mut().sem_trivial_lease_fut), cx)
242 .map_ok(|sem_trivial_lease_guard| AsyncRwLockReadGuard {
243 sem_trivial_lease_guard,
244 })
245 .map_err(AsyncRwLockError::from)
246 }
247}
248
249pub struct AsyncRwLockReadGuard<
257 ST: sync_types::SyncTypes,
258 T: marker::Send + marker::Sync,
259 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>,
260> {
261 sem_trivial_lease_guard: semaphore::AsyncSemaphoreLeasesGuard<
262 ST,
263 T,
264 sync_types::SyncRcPtrForInner<AsyncRwLock<ST, T>, LP, AsyncRwLockIndexInnerSemTag>,
265 >,
266}
267
268impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
269 AsyncRwLockReadGuard<ST, T, LP>
270{
271 pub fn get_rwlock(&self) -> LP::SyncRcPtrRef<'_> {
273 self.sem_trivial_lease_guard.get_semaphore().get_container().clone()
274 }
275
276 pub fn into_rwlock(self) -> LP {
278 self.sem_trivial_lease_guard.into_semaphore().into_container()
279 }
280
281 pub fn into_weak(self) -> AsyncRwLockReadWeakGuard<ST, T, LP> {
284 AsyncRwLockReadWeakGuard {
285 sem_trivial_lease_guard: Some(self.sem_trivial_lease_guard.into_weak()),
286 }
287 }
288
289 fn into_raw(this: Self) -> *const T {
294 let (ptr, leases_granted) = this.sem_trivial_lease_guard.into_raw();
295 debug_assert_eq!(leases_granted, 0);
296 ptr
297 }
298
299 unsafe fn from_raw(ptr: *const T) -> Self {
307 let sem_trivial_lease_guard = unsafe { semaphore::AsyncSemaphoreLeasesGuard::from_raw(ptr, 0) };
308 Self {
309 sem_trivial_lease_guard,
310 }
311 }
312}
313
314impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
315 ops::Deref for AsyncRwLockReadGuard<ST, T, LP>
316{
317 type Target = T;
318
319 fn deref(&self) -> &Self::Target {
320 &self.sem_trivial_lease_guard
321 }
322}
323
324impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>> Clone
325 for AsyncRwLockReadGuard<ST, T, LP>
326{
327 fn clone(&self) -> Self {
328 let sem_trivial_lease_guard = self.sem_trivial_lease_guard.spawn_trivial_lease();
329 Self {
330 sem_trivial_lease_guard,
331 }
332 }
333}
334
335pub struct AsyncRwLockReadWeakGuard<
346 ST: sync_types::SyncTypes,
347 T: marker::Send + marker::Sync,
348 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>,
349> {
350 #[allow(clippy::type_complexity)]
351 sem_trivial_lease_guard: Option<
352 semaphore::AsyncSemaphoreLeasesWeakGuard<
353 ST,
354 T,
355 sync_types::SyncRcPtrForInner<AsyncRwLock<ST, T>, LP, AsyncRwLockIndexInnerSemTag>,
356 >,
357 >,
358}
359
360impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
361 AsyncRwLockReadWeakGuard<ST, T, LP>
362{
363 pub fn upgrade(self) -> Option<AsyncRwLockReadGuard<ST, T, LP>> {
368 self.sem_trivial_lease_guard
369 .and_then(|sem_trivial_lease_guard| sem_trivial_lease_guard.upgrade())
370 .map(|sem_trivial_lease_guard| AsyncRwLockReadGuard {
371 sem_trivial_lease_guard,
372 })
373 }
374
375 fn upgrade_by_ref(&self) -> Option<AsyncRwLockReadGuard<ST, T, LP>> {
380 self.sem_trivial_lease_guard
381 .as_ref()
382 .and_then(|sem_trivial_lease_guard| sem_trivial_lease_guard.try_spawn_trivial_lease())
383 .map(|sem_trivial_lease_guard| AsyncRwLockReadGuard {
384 sem_trivial_lease_guard,
385 })
386 }
387
388 fn into_raw(mut this: Self) -> *const T {
398 this.sem_trivial_lease_guard
399 .take()
400 .map(|sem_trivial_lease_guard| {
401 let (ptr, leases_granted) = sem_trivial_lease_guard.into_raw();
402 debug_assert_eq!(leases_granted, 0);
403 ptr
404 })
405 .unwrap_or(ptr::null())
406 }
407
408 unsafe fn from_raw(ptr: *const T) -> Self {
416 if !ptr.is_null() {
417 let sem_trivial_lease_guard = unsafe { semaphore::AsyncSemaphoreLeasesWeakGuard::from_raw(ptr, 0) };
418 Self {
419 sem_trivial_lease_guard: Some(sem_trivial_lease_guard),
420 }
421 } else {
422 Self {
423 sem_trivial_lease_guard: None,
424 }
425 }
426 }
427}
428
429impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>> Clone
430 for AsyncRwLockReadWeakGuard<ST, T, LP>
431{
432 fn clone(&self) -> Self {
433 let sem_trivial_lease_guard = self
434 .sem_trivial_lease_guard
435 .as_ref()
436 .and_then(|sem_trivial_lease_guard| sem_trivial_lease_guard.try_spawn_trivial_lease())
437 .map(|sem_trivial_lease_guard| sem_trivial_lease_guard.into_weak());
438 Self {
439 sem_trivial_lease_guard,
440 }
441 }
442}
443
444pub struct AsyncRwLockReadGuardForInner<
459 ST: sync_types::SyncTypes,
460 OT,
461 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>,
462 TAG,
463> where
464 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
465 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
466{
467 guard_for_outer: AsyncRwLockReadGuard<ST, OT, LP>,
468 _phantom: marker::PhantomData<fn() -> TAG>,
469}
470
471impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG> Clone
472 for AsyncRwLockReadGuardForInner<ST, OT, LP, TAG>
473where
474 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
475 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
476{
477 fn clone(&self) -> Self {
478 Self {
479 guard_for_outer: self.guard_for_outer.clone(),
480 _phantom: marker::PhantomData,
481 }
482 }
483}
484
485impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG>
486 convert::From<AsyncRwLockReadGuard<ST, OT, LP>> for AsyncRwLockReadGuardForInner<ST, OT, LP, TAG>
487where
488 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
489 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
490{
491 fn from(value: AsyncRwLockReadGuard<ST, OT, LP>) -> Self {
492 Self {
493 guard_for_outer: value,
494 _phantom: marker::PhantomData,
495 }
496 }
497}
498
499impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG> ops::Deref
500 for AsyncRwLockReadGuardForInner<ST, OT, LP, TAG>
501where
502 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
503 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
504{
505 type Target = <OT as sync_types::DerefInnerByTag<TAG>>::Output;
506
507 fn deref(&self) -> &Self::Target {
508 <OT as sync_types::DerefInnerByTag<TAG>>::deref_inner(&self.guard_for_outer)
509 }
510}
511
512impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG>
513 sync_types::SyncRcPtr<<OT as sync_types::DerefInnerByTag<TAG>>::Output>
514 for AsyncRwLockReadGuardForInner<ST, OT, LP, TAG>
515where
516 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
517 <OT as sync_types::DerefInnerByTag<TAG>>::Output: Sized + marker::Send + marker::Sync,
518{
519 type WeakSyncRcPtr = AsyncRwLockReadWeakGuardForInner<ST, OT, LP, TAG>;
520
521 type SyncRcPtrRef<'a>
522 = sync_types::GenericSyncRcPtrRef<'a, <OT as sync_types::DerefInnerByTag<TAG>>::Output, Self>
523 where
524 Self: 'a;
525
526 fn downgrade(&self) -> Self::WeakSyncRcPtr {
527 Self::WeakSyncRcPtr::from(self.guard_for_outer.clone().into_weak())
528 }
529
530 fn into_raw(this: Self) -> *const <OT as sync_types::DerefInnerByTag<TAG>>::Output {
531 let ptr_to_outer = AsyncRwLockReadGuard::into_raw(this.guard_for_outer);
532 <OT as sync_types::DerefInnerByTag<TAG>>::to_inner_ptr(ptr_to_outer)
533 }
534
535 unsafe fn from_raw(ptr: *const <OT as sync_types::DerefInnerByTag<TAG>>::Output) -> Self {
536 let ptr_to_outer = unsafe { <OT as sync_types::DerefInnerByTag<TAG>>::container_of(ptr) };
537 let guard_for_outer = unsafe { AsyncRwLockReadGuard::from_raw(ptr_to_outer) };
538 Self {
539 guard_for_outer,
540 _phantom: marker::PhantomData,
541 }
542 }
543}
544
545pub struct AsyncRwLockReadWeakGuardForInner<
553 ST: sync_types::SyncTypes,
554 OT,
555 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>,
556 TAG,
557> where
558 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
559 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
560{
561 guard_for_outer: AsyncRwLockReadWeakGuard<ST, OT, LP>,
562 _phantom: marker::PhantomData<fn() -> TAG>,
563}
564
565impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG> Clone
566 for AsyncRwLockReadWeakGuardForInner<ST, OT, LP, TAG>
567where
568 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
569 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
570{
571 fn clone(&self) -> Self {
572 Self {
573 guard_for_outer: self.guard_for_outer.clone(),
574 _phantom: marker::PhantomData,
575 }
576 }
577}
578
579impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG>
580 convert::From<AsyncRwLockReadWeakGuard<ST, OT, LP>> for AsyncRwLockReadWeakGuardForInner<ST, OT, LP, TAG>
581where
582 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
583 <OT as sync_types::DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
584{
585 fn from(value: AsyncRwLockReadWeakGuard<ST, OT, LP>) -> Self {
586 Self {
587 guard_for_outer: value,
588 _phantom: marker::PhantomData,
589 }
590 }
591}
592
593impl<ST: sync_types::SyncTypes, OT, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, OT>>, TAG>
594 sync_types::WeakSyncRcPtr<
595 <OT as sync_types::DerefInnerByTag<TAG>>::Output,
596 AsyncRwLockReadGuardForInner<ST, OT, LP, TAG>,
597 > for AsyncRwLockReadWeakGuardForInner<ST, OT, LP, TAG>
598where
599 OT: sync_types::DerefInnerByTag<TAG> + marker::Send + marker::Sync,
600 <OT as sync_types::DerefInnerByTag<TAG>>::Output: Sized + marker::Send + marker::Sync,
601{
602 fn upgrade(&self) -> Option<AsyncRwLockReadGuardForInner<ST, OT, LP, TAG>> {
603 self.guard_for_outer
604 .upgrade_by_ref()
605 .map(|guard_for_outer| AsyncRwLockReadGuardForInner {
606 guard_for_outer,
607 _phantom: marker::PhantomData,
608 })
609 }
610
611 fn into_raw(this: Self) -> *const <OT as sync_types::DerefInnerByTag<TAG>>::Output {
612 let ptr_to_outer = AsyncRwLockReadWeakGuard::into_raw(this.guard_for_outer);
613 if !ptr_to_outer.is_null() {
614 <OT as sync_types::DerefInnerByTag<TAG>>::to_inner_ptr(ptr_to_outer)
615 } else {
616 ptr::null()
617 }
618 }
619
620 unsafe fn from_raw(ptr: *const <OT as sync_types::DerefInnerByTag<TAG>>::Output) -> Self {
621 let ptr_to_outer = if !ptr.is_null() {
622 unsafe { <OT as sync_types::DerefInnerByTag<TAG>>::container_of(ptr) }
623 } else {
624 ptr::null()
625 };
626 let guard_for_outer = unsafe { AsyncRwLockReadWeakGuard::from_raw(ptr_to_outer) };
627 Self {
628 guard_for_outer,
629 _phantom: marker::PhantomData,
630 }
631 }
632}
633
634pub struct AsyncRwLockWriteFuture<
646 ST: sync_types::SyncTypes,
647 T: marker::Send + marker::Sync,
648 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>,
649> {
650 sem_exclusive_all_fut: semaphore::AsyncSemaphoreExclusiveAllFuture<
651 ST,
652 T,
653 sync_types::SyncRcPtrForInner<AsyncRwLock<ST, T>, LP, AsyncRwLockIndexInnerSemTag>,
654 >,
655}
656
657impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
658 AsyncRwLockWriteFuture<ST, T, LP>
659{
660 pub fn get_rwlock(&self) -> Option<LP> {
661 self.sem_exclusive_all_fut
662 .get_semaphore()
663 .map(|sem| sem.into_container())
664 }
665}
666
667impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
668 marker::Unpin for AsyncRwLockWriteFuture<ST, T, LP>
669{
670}
671
672impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
673 future::Future for AsyncRwLockWriteFuture<ST, T, LP>
674{
675 type Output = Result<AsyncRwLockWriteGuard<ST, T, LP>, AsyncRwLockError>;
676
677 fn poll(self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
685 future::Future::poll(pin::Pin::new(&mut self.get_mut().sem_exclusive_all_fut), cx)
686 .map_ok(|sem_exclusive_all_guard| AsyncRwLockWriteGuard {
687 sem_exclusive_all_guard,
688 })
689 .map_err(AsyncRwLockError::from)
690 }
691}
692
693pub struct AsyncRwLockWriteGuard<
695 ST: sync_types::SyncTypes,
696 T: marker::Send + marker::Sync,
697 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>,
698> {
699 sem_exclusive_all_guard: semaphore::AsyncSemaphoreExclusiveAllGuard<
700 ST,
701 T,
702 sync_types::SyncRcPtrForInner<AsyncRwLock<ST, T>, LP, AsyncRwLockIndexInnerSemTag>,
703 >,
704}
705
706impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
707 AsyncRwLockWriteGuard<ST, T, LP>
708{
709 pub fn get_rwlock(&self) -> LP::SyncRcPtrRef<'_> {
711 self.sem_exclusive_all_guard.get_semaphore().get_container().clone()
712 }
713
714 pub fn into_rwlock(self) -> LP {
716 self.sem_exclusive_all_guard.into_semaphore().into_container()
717 }
718
719 pub fn into_weak(self) -> AsyncRwLockWriteWeakGuard<ST, T, LP> {
722 AsyncRwLockWriteWeakGuard {
723 sem_exclusive_all_guard: self.sem_exclusive_all_guard.into_weak(),
724 }
725 }
726
727 pub fn borrow_outer_inner_mut<'a>(&'a mut self) -> (LP::SyncRcPtrRef<'a>, &'a mut T) {
743 let (sem, v) = self.sem_exclusive_all_guard.borrow_outer_inner_mut();
744 (sem.get_container().clone(), v)
745 }
746}
747
748impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
749 ops::Deref for AsyncRwLockWriteGuard<ST, T, LP>
750{
751 type Target = T;
752
753 fn deref(&self) -> &Self::Target {
754 &self.sem_exclusive_all_guard
755 }
756}
757
758impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
759 ops::DerefMut for AsyncRwLockWriteGuard<ST, T, LP>
760{
761 fn deref_mut(&mut self) -> &mut Self::Target {
762 &mut self.sem_exclusive_all_guard
763 }
764}
765
766pub struct AsyncRwLockWriteWeakGuard<
777 ST: sync_types::SyncTypes,
778 T: marker::Send + marker::Sync,
779 LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>,
780> {
781 sem_exclusive_all_guard: semaphore::AsyncSemaphoreExclusiveAllWeakGuard<
782 ST,
783 T,
784 sync_types::SyncRcPtrForInner<AsyncRwLock<ST, T>, LP, AsyncRwLockIndexInnerSemTag>,
785 >,
786}
787
788impl<ST: sync_types::SyncTypes, T: marker::Send + marker::Sync, LP: sync_types::SyncRcPtr<AsyncRwLock<ST, T>>>
789 AsyncRwLockWriteWeakGuard<ST, T, LP>
790{
791 pub fn upgrade(self) -> Option<AsyncRwLockWriteGuard<ST, T, LP>> {
796 self.sem_exclusive_all_guard
797 .upgrade()
798 .map(|sem_exclusive_all_guard| AsyncRwLockWriteGuard {
799 sem_exclusive_all_guard,
800 })
801 }
802}