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 DD37525784E; Tue, 28 Oct 2025 19:33:33 +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=1761680014; cv=none; b=bwhMLbSVPJot7qwi/C/6667fMdzavYt/HksKTALT6PH0CGi1RmGRi54y7A1Myyu7HZCPL3aFmsH2hSsURNmNxoA3XTyeXI9GJ6Qbv8/XK5BJEVT8JHLIT/JPQDvqnTZovysGwAWH5KyA7xzL6vojRvVoSodrEqFQNQtIrhRCVi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761680014; c=relaxed/simple; bh=/aaILh4Sb4dqcUqp6HGcNIrngphl1Uu0/ZivAdehfH0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LiuG8rMOS+11PK+GsOKKOsTP5Rb9uoCdk0yLMubj3hqk+vqiwbjq+f3BocKuJPcvRAC8TI2KzI9EufhjMeY91Oz7i3uHETQghCWXT5deqTMVrs5Mpa9evF9woE+aFoyR2TJ/w3ziIshe0e6naMev4tD6zX1PVHTqbAiTnEJgi+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f/AJOvJy; 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="f/AJOvJy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2C4C4CEE7; Tue, 28 Oct 2025 19:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761680013; bh=/aaILh4Sb4dqcUqp6HGcNIrngphl1Uu0/ZivAdehfH0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=f/AJOvJyoe4eD9ZjS71zbvG32E4Nnwbvgbpd3LwmI0SZ7fJ/Ot5VbfI33Co5NJmUO 43PbDLJQjAKJcaeTD2/I8YtP8I+qa4LM3bEYQJrKy5rhnblF3tTrVsnZfcfUd7bfdk eaaROZrXu1g1ZtiSTgU7d2bgUu/F7Opbw2SB4Rtm52vUayN7VEssFwvZAkGtTDt/8i Nrl2EpRYR1nOCLvYCKvNPi54/A5J0QGSWmGvQQmPk1R21HpGK856JYVorXsJvRWIfR 1vtCoZarVhrbX7d/38U/dAPPBbHVGViEK9Fs65StZUG1VHlSQVYNuUikuIXRDkrxN4 FiQ1SISXaPhCQ== Message-ID: Date: Tue, 28 Oct 2025 20:33:27 +0100 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/5] rust: id_pool: do not immediately acquire new ids To: Alice Ryhl Cc: Greg Kroah-Hartman , Yury Norov , =?UTF-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Burak Emir , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org References: <20251028-binder-bitmap-v3-0-32822d4b3207@google.com> <20251028-binder-bitmap-v3-4-32822d4b3207@google.com> From: Danilo Krummrich Content-Language: en-US In-Reply-To: <20251028-binder-bitmap-v3-4-32822d4b3207@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/28/25 11:55 AM, Alice Ryhl wrote: > +/// Represents an unused id in an [`IdPool`]. > +pub struct UnusedId<'pool> { > + id: usize, > + pool: &'pool mut IdPool, > +} > + > +impl<'pool> UnusedId<'pool> { > + /// Get the unused id as an usize. > + /// > + /// Be aware that the id has not yet been acquired in the pool. The > + /// [`acquire`] method must be called to prevent others from taking the id. > + #[inline] > + #[must_use] > + pub fn as_usize(&self) -> usize { > + self.id > + } > + > + /// Get the unused id as an u32. > + /// > + /// Be aware that the id has not yet been acquired in the pool. The > + /// [`acquire`] method must be called to prevent others from taking the id. > + #[inline] > + #[must_use] > + pub fn as_u32(&self) -> u32 { > + // CAST: The maximum possible value in an IdPool is i32::MAX. I think this should rather be an invariant of `UnusedId`. Reviewed-by: Danilo Krummrich > + self.id as u32 > + }