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 94ACB2798EA; Wed, 16 Jul 2025 17:16:09 +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=1752686169; cv=none; b=Mf3NKJbbRxO6WQ/bpzqtjqvgwCmPUa3jIFKM1HaQ9FSW38/0yAJ0N2mZsvEFO1D7McfWKC3Q4BvmOw1Boh65sxK/tKWIYviv9AM/pAH2L/ScvAFSA4JB7G9CId7jnsGbnZkaI2GJ1JGjvbtee+CE0hlvMc8yaqvAV8jBfuwbq8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752686169; c=relaxed/simple; bh=WjN4ZftabKpQLXbiJ4dykt/E4neOL6d8HDXxD+KsYsg=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=gz89g86y6qeZ0WGWR5atkn1xMcAU0/zTqBNNfEmD4nVBEU4gFKrIz+wrL5avAvG0cgM5OxSX0abojQf2ZoOTRZ120IH7umiuu1j1qYRGN5yjvU120pHkLcVSf6Bd0PoqPQ/+Vc2qFW8WsEDJBGbxj4e/P6AsEN7b9bGNeP/YOqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IA/Ii8Gr; 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="IA/Ii8Gr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51355C4CEE7; Wed, 16 Jul 2025 17:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752686169; bh=WjN4ZftabKpQLXbiJ4dykt/E4neOL6d8HDXxD+KsYsg=; h=Date:To:Cc:Subject:From:References:In-Reply-To:From; b=IA/Ii8Gr1Za8zAw0xmiaujSA2tjTH3ppWsobaRIC5xDJ4lz7/LrX4Z/YNh6SuUInl PMK4HGV001yLzrsg2LbYEhx9By4cRSW+CzwnX91J7W3NENGjWiRfqTaL/ohM7opau7 jWxomSpQgWYJvxuWslffSJNpagRcv8Z2zgIQ7HgBWJaqnYyKHICkrih+m3reZPVlQF Q6ZuEnAtWuShSi9+SRKHv7M1Dq+4VcA8IFTAE04YpsK5gFXu7Xr0uOO4MM/wdH1BZY q7y+vcAjXZ+usJdExDd5IE80beP7X6xVLW8Skoknj8UAHGek0ZL9YrFIqOMBf8v9XS 2WPgTnoMYEImg== Precedence: bulk X-Mailing-List: linux-arch@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, 16 Jul 2025 19:16:02 +0200 Message-Id: To: "Boqun Feng" Cc: , , , , "Miguel Ojeda" , "Alex Gaynor" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Will Deacon" , "Peter Zijlstra" , "Mark Rutland" , "Wedson Almeida Filho" , "Viresh Kumar" , "Lyude Paul" , "Ingo Molnar" , "Mitchell Levy" , "Paul E. McKenney" , "Greg Kroah-Hartman" , "Linus Torvalds" , "Thomas Gleixner" , "Alan Stern" Subject: Re: [PATCH v7 6/9] rust: sync: atomic: Add the framework of arithmetic operations From: "Benno Lossin" X-Mailer: aerc 0.20.1 References: <20250714053656.66712-7-boqun.feng@gmail.com> In-Reply-To: On Wed Jul 16, 2025 at 5:48 PM CEST, Boqun Feng wrote: > On Wed, Jul 16, 2025 at 05:36:05PM +0200, Benno Lossin wrote: > [..] >> > >> > I have a better solution: >> > >> > in ops.rs >> > >> > pub struct AtomicRepr(UnsafeCell) >> > >> > impl AtomicArithmeticOps for i32 { >> > // a *safe* function >> > fn atomic_add(a: &AtomicRepr, v: i32) { >> > ... >> > } >> > } >> > >> > in generic.rs >> > >> > pub struct Atomic(AtoimcRepr); >> > >> > impl Atomic { >> > fn add(&self, v: .., ...) { >> > T::Repr::atomic_add(&self.0, ...); >> > } >> > } >> > >> > see: >> > >> > https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/log/?= h=3Drust-atomic-impl >>=20 >> Hmm what does the additional indirection give you? >>=20 > > What additional indirection you mean? You cannot make atomic_add() safe > with only `UnsafeCell`. What is the advantage of making it safe? It just moves the safety comments into `ops.rs` which makes it harder to read due to the macros. --- Cheers, Benno