From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5FEE23770D; Wed, 9 Jul 2025 18:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752085343; cv=none; b=c/Cmg77+rbBd7Hs78sC26ZSky3vop0KTXLxKc52wxw6ZRmK49t6zBHxPMP6SAT6ApxnAy69kL5lbxh3x/HsH2kmVGf+9im0/bfcAlUAM0U+btpiT0oizPm9FcPki9NuA+WPrHB7SWQ4Yx5nz4Hsto4xhP5QwDY9w2nOvoAH6qVE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752085343; c=relaxed/simple; bh=5CLAa7B3mPRRniciO0gLisy8WVRITPjA7SLk6e8ROHk=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=Jkq2xjiC/q7w8GogUe46XOFIuvIN47Q9Ijknsf5n7ljC5GfFlLRsUm1MK6c/WP2o18QRVrLNrpSsUR+m/UzEWXjG+B1Lt3QN4WiOq0Lq0JhTIaBjg1eIMfCzDnErhEaEk9e27ka/+fMizHTx6+txARA0eEerFioYs8Iku333xsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pfS/aFI9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pfS/aFI9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 892DDC4CEEF; Wed, 9 Jul 2025 18:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752085343; bh=5CLAa7B3mPRRniciO0gLisy8WVRITPjA7SLk6e8ROHk=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=pfS/aFI9iB0IO4L8LVGX6W06JqphTp4Lxw79qYY49GgGIB38Oy0WZcMin9enqTSBT emzKnZjXoCjbZAh7x3/2UmFbFZSdU7jTJLoHx8ydf0OwO/mA5MwQJKl5fXvi03ztA8 Pa4emYLgCs7oFecZgD0imV2R0eXbigzLpyBKfQQ/oaZReheIQDhbePnbaegs5ODSOV 7pZoKyglDVwZelrKKJTYz+bpzzoN2VGPaQAbneiM0SpXeMKOvI0DDG7u1Mm5ogFlj/ pO2BFBjGWWscoHwHn/v66QhcSMef/FPZjfShVzSnAdG80V0XPCz/bjYmpQz88w59ac 1dCRiuCXP0m3w== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 09 Jul 2025 20:22:16 +0200 Message-Id: Cc: "Boqun Feng" , "Alice Ryhl" , "Miguel Ojeda" , "Alex Gaynor" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Masahiro Yamada" , "Nathan Chancellor" , "Luis Chamberlain" , "Danilo Krummrich" , "Nicolas Schier" , "Trevor Gross" , "Adam Bratschi-Kaye" , , , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , "Fiona Behrens" , "Daniel Almeida" , Subject: Re: [PATCH v15 1/7] rust: sync: add `SetOnce` From: "Benno Lossin" To: "Andreas Hindborg" X-Mailer: aerc 0.20.1 References: <20250707-module-params-v3-v15-0-c1f4269a57b9@kernel.org> <20250707-module-params-v3-v15-1-c1f4269a57b9@kernel.org> <877c0joyfo.fsf@kernel.org> <87ple9lkjr.fsf@kernel.org> In-Reply-To: <87ple9lkjr.fsf@kernel.org> On Wed Jul 9, 2025 at 12:34 PM CEST, Andreas Hindborg wrote: > "Benno Lossin" writes: >> On Tue Jul 8, 2025 at 10:54 AM CEST, Andreas Hindborg wrote: >>> "Boqun Feng" writes: >>>> On Mon, Jul 07, 2025 at 03:38:58PM +0200, Alice Ryhl wrote: >>>>> On Mon, Jul 7, 2025 at 3:32=E2=80=AFPM Andreas Hindborg wrote: >>>>> > >>>>> > Introduce the `SetOnce` type, a container that can only be written = once. >>>>> > The container uses an internal atomic to synchronize writes to the = internal >>>>> > value. >>>>> > >>>>> > Signed-off-by: Andreas Hindborg >>>>> >>>>> LGTM: >>>>> Reviewed-by: Alice Ryhl >>>>> >>>>> > +impl Drop for SetOnce { >>>>> > + fn drop(&mut self) { >>>>> > + if self.init.load(Acquire) =3D=3D 2 { >>>>> > + // SAFETY: By the type invariants of `Self`, `self.ini= t =3D=3D 2` means that `self.value` >>>>> > + // contains a valid value. We have exclusive access, a= s we hold a `mut` reference to >>>>> > + // `self`. >>>>> > + unsafe { drop_in_place(self.value.get()) }; >>>>> >>>>> This load does not need to be Acquire. It can be a Relaxed load or >>>>> even an unsynchronized one since the access is exclusive. >>>> >>>> Right, I think we can do the similar as Revocable here: >>>> >>>> if *self.init.get_mut() =3D=3D 2 { } > > Ok, now I got it. You are saying I don't need to use the atomic load > method, because I have mutable access. Sounds good. > > But I guess a relaxed load and access through a mutable reference should > result in the same code generation on most (all?) platforms? AFAIK it is not the same on arm. --- Cheers, Benno