From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 963D7381AF for ; Mon, 16 Feb 2026 08:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771231600; cv=none; b=qOq5sP7cwZ0vUnv5RfL82Ci6JuPBXsKCwbHiSZlyJX7i3HJXRmmi4Sfs68zPfUlRnAo6BsebQ8/phzYuA/e8HjAPTYtQA/j0vC5J4jMSCGi10vrjHrqJ4dp3ZDTRWWbIAwvtRTOM+BiSZ3vMOLxTboiQthV+RFz7eO0H9YpqJcA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771231600; c=relaxed/simple; bh=mbjq+FRK2nX6+tBicVOsRK0dghmKmeXV81hETpPKXZI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HJHWO8beU4qKT4KpD6jFvCnP7TUtf5An1caJ1wpq/An5VsYYp8iKx4uZEENbLUeZCI8GS7e0/LIj27o1ivjEM2VvKKxkVZGiFjFSGRDEcdfUkqbLlnzsGro0UbowuaCBVtOrgJ+mrd0IyaTmkarSccGXKdZmUsPtM/YHqxagV4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LADhozhe; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LADhozhe" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-482d8e6e13aso20305755e9.3 for ; Mon, 16 Feb 2026 00:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771231598; x=1771836398; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LPGO6IK6vf6m310aknJYPg6oVbAt+vYuSFArBMF374E=; b=LADhozheDn3VSiseFQMHoUqxFghjx5jhJkhFkns4kxu/jk8vJjgYjvzkPTbcRo475I 4P7LJheAHsNRnVc8qulwRi68zb/u2qGcS8Q5mF9Zh7lfQwJ8gwNdM1agFlWYr+DjP+6P 9mWDs7GFzRYGLu/K7Mr6bjoDFI2nmD9pK8Ks99wmlFUve2HzuWPQLw3sJy9UKsPvpJ5G tRp3rxWQ91DHShJx7pz0TOS95hOdSqoRJr7inzZ/a3ziMBtqqcKTU96RC0aruqQ5vFnt fTVJxTcPbF0T5LYhnZVpJrzBXN2Pn9jv5uFIws5fd3wv9fPbuFUIa3ftVcFvp6qQ8QiJ hUHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771231598; x=1771836398; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LPGO6IK6vf6m310aknJYPg6oVbAt+vYuSFArBMF374E=; b=Xw4KwOw2KFzE1HMLFoaqluO97VlK1C3Ta8z4AGK9mHeWTKgrrMrlskxg5HcemDUGR3 kPoDJMn+RoGYlh0ORYD/l9yms7HEl+bRrM/DwqpneTZtxRbfi15FU7mYrd7n7rNLjd1e wFwogHT/MyFJ6wOFzsPhQEO3th9BkQIH1HpZ+EjgjKsSzzPgLHO/rTiKmFBXr08zBCzk s7Q6nq+7HHylbzCvl00d2zcsMvjXrTPj9TxE2/PJyT5yNCPZTKRMCaSHWP0M09H4/1m3 93tdZ5RpHWJPaz+BHVYTz/xbvIxA9OVwI2KwD+WE4wdkhWjdR/9xABTlq24rW+bNPOWH ZGLQ== X-Forwarded-Encrypted: i=1; AJvYcCXyphwf/8mqMc2eY3vFdC0GsPDFPCDoK7/XjZwyVc2mT6Wb6Km7GUxnXMGOvX9TTRVODGBlxbJzUmepFw0=@vger.kernel.org X-Gm-Message-State: AOJu0YwR9b5d+/x/OwObPq/ovURfNb4SkvgjYToHQybj4LcmUUh2EB6D czvZZbq7npUotyrS7D8vz0LhSE+9NgnMo+73wcJrELOR4OAa5YWgCtsskItTvTSxHGGD3n3IbdT 2LDziZHiDgeUxzFJn+A== X-Received: from wmjs7.prod.google.com ([2002:a7b:c387:0:b0:47e:e4f5:36ca]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:5294:b0:483:8062:b2f with SMTP id 5b1f17b1804b1-48380620cf2mr78995575e9.6.1771231597785; Mon, 16 Feb 2026 00:46:37 -0800 (PST) Date: Mon, 16 Feb 2026 08:46:36 +0000 In-Reply-To: <20260215-set-once-lazy-v1-1-6f5bd2efda11@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260215-set-once-lazy-v1-1-6f5bd2efda11@kernel.org> Message-ID: Subject: Re: [PATCH] rust: sync: add lazy initialization methods to SetOnce From: Alice Ryhl To: Andreas Hindborg Cc: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Trevor Gross , Danilo Krummrich , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Sun, Feb 15, 2026 at 09:27:17PM +0100, Andreas Hindborg wrote: > Add methods to get a reference to the contained value or populate the > SetOnce if empty. The new `as_ref_or_populate` method accepts a value > directly, while `as_ref_or_populate_with` accepts a fallible closure, > allowing for lazy initialization that may fail. Both methods spin-wait > if another thread is concurrently initializing the container. > > Also add `populate_with` which takes a fallible closure and serves as > the implementation basis for the other populate methods. > > Signed-off-by: Andreas Hindborg > + /// Get a reference to the contained object, or populate the [`SetOnce`] > + /// with the value returned by `callable` and return a reference to that > + /// object. > + pub fn as_ref_or_populate_with(&self, callable: impl FnOnce() -> Result) -> Result<&T> { > + if !self.populate_with(callable)? { > + while self.init.load(Acquire) != 2 { > + core::hint::spin_loop(); > + } We should not be implementing our own spinlocks. Alice