From 74aefa0b0701ea186cd4ff5149466e61a380dcb1 Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Mon, 28 Aug 2023 13:59:08 +0300 Subject: [PATCH] heavier_once_cell: explain away the unsynchornized --- libs/utils/src/sync/heavier_once_cell.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/utils/src/sync/heavier_once_cell.rs b/libs/utils/src/sync/heavier_once_cell.rs index 4b279f2e98..03011f7016 100644 --- a/libs/utils/src/sync/heavier_once_cell.rs +++ b/libs/utils/src/sync/heavier_once_cell.rs @@ -1,10 +1,13 @@ use std::sync::{Arc, Mutex, MutexGuard}; use tokio::sync::Semaphore; -/// Custom design like [`tokio::sync::OnceCell`] but with extra [`Arc`]s for unsynchronized -/// initialization and deinitialization. +/// Custom design like [`tokio::sync::OnceCell`] but using [`OwnedSemaphorePermit`] instead of +/// `SemaphorePermit`, allowing use of `take` which does not require holding an outer mutex guard +/// for the duration of initialization. /// /// Has no unsafe, builds upon [`tokio::sync::Semaphore`] and [`std::sync::Mutex`]. +/// +/// [`OwnedSemaphorePermit`]: tokio::sync::OwnedSemaphorePermit pub struct OnceCell { inner: Mutex>, }