Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4260574rwd; Tue, 23 May 2023 05:38:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jlqlju24m35JSwj+Gs+QeEu3ThDvQMyhlfeqt2KIf0WgBS2Hfk+vnS9yrB1zTOWWq8fKs X-Received: by 2002:a17:90a:5303:b0:24e:4b1c:74d2 with SMTP id x3-20020a17090a530300b0024e4b1c74d2mr13427374pjh.32.1684845480608; Tue, 23 May 2023 05:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684845480; cv=none; d=google.com; s=arc-20160816; b=BghOSZ/aRAeevyk/WqknMDC14weyZxTiIJEjfQjwQ0kcLw1XBGUZugK+P/zHuiQs+T stecptRfLqjBourS80VZEMhTvIq2xfSJzuZ6mu7bbJ66c27JKcEvgFLbdC+jhe80Clcw Uas7zLOquQ9q8sFQuUr/+Jf4AchaEV0owQb4HsFQHs/QUVHkqoGbXm6GUOpsYs4gD4sQ UllM40NSypBGVKEV7jCteULgJRQV89hlVna6K4myJSLoVaUAvHSMLmy/l+7WZe8KboV1 4j8Ed4TKBHJz894rFHc85S2cDhX9zxiZlHvkTDTPZjoHC93rCH4D4Qr04RFRNWlSGFSw VsZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=BtyIsC3fOFjgjr9w9nc1ft0SzM61Czn4H/P3GjzNfK0=; b=w70tq8nFDFmDQnZL7kOuS7dA165raIW4Ng3HZnyQ41jKc/HdtAPNLSBAQVa+Hvo1vq nIOugC1mC512lz5ZsRSsxZyVL6SgxB9rAZ0/23gi72z+xluRfmf/hFlclmNWUncIOvgo YU24+4mbXhwnNZAkD3umti/NgfyI7LmGmv0PteGgnFHzPHsagMDTG1NS9o7CT8yNb6Ci 2/w9oaVtSMyHahngVq2xwLRJXZTeoTh6QaaeWh7dx2ElYc/4E12opaAvzvvOHmhZxt0C uhKqO5n5NWwTgI7eYPiMNM25RnCcpirpxvLbAODTsGZs330UWxr0UWebhlN9YZ8Bgmdb umrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=bdm9uKxS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a637a01000000b0052c75ef69b1si6259940pgc.825.2023.05.23.05.37.47; Tue, 23 May 2023 05:38:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=bdm9uKxS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236720AbjEWMAJ (ORCPT + 99 others); Tue, 23 May 2023 08:00:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbjEWMAH (ORCPT ); Tue, 23 May 2023 08:00:07 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEB4120 for ; Tue, 23 May 2023 04:59:59 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-51190fd46c3so1223231a12.1 for ; Tue, 23 May 2023 04:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1684843198; x=1687435198; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=BtyIsC3fOFjgjr9w9nc1ft0SzM61Czn4H/P3GjzNfK0=; b=bdm9uKxSj9wOh8IC4/CRZXk1vTYZPuOEBSXUGk5gfmyUqA04txmm/wMX2tbxYblfo/ VgGFH28rswMT6qcXru0NTDMd968EfXKd0RfJdqHc/niQ8AwLwed+fZaXNUznLagqZbwg 7tkhI27bpz4eiIwUfdiHFO7uQifd5MbaSz6e0ibXSTApTSa8NBTDHQJHgCUk2DVTyQI/ Bhwvb2prpfZ4YmRqKJmCGC0JRIo/MNzR+lj4ezo0xkoA8HG7md65l3yse6l799w04aVm h2fzstPqo2J+mX+CjAoPnNAa3iTwdk9btrQ7CiKMUKWCHnTiA+7U7+ALOmn5KW3ty3Y2 3ZuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684843198; x=1687435198; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BtyIsC3fOFjgjr9w9nc1ft0SzM61Czn4H/P3GjzNfK0=; b=SDJiDbPkKhcSOGoVxggIvbW8aN4rjgqVXr9RFqEVjsafzFhFux81haUH2/QyQ6VF5c JdyVJzirvsVMhan53B51gY/E32ldgR/XiDzxMXtMtM3r2mUeQ6caqSwZVMpuMYIhb/2y YMJJDcPRVF4DaP7Tt8nyMo7CfI/J+L725pZIaCx/sAYBUjqYHdY+Ongov9vHATBTM1hL SQmKfPD309p9jSFejAmpa8lcPe2k89wtxDzodgzkQSeH+x0pyGfynI8egM0Y3/qtAIJZ wT5wL3sONqSZKkuasoMDp1dZ0gk+GyvM/+3DvKyUBzZLiODy9xrhdcEonwuXwcaOncMn ZG2g== X-Gm-Message-State: AC+VfDxAzJy628E+f8SM1lzIHTzdMSSdeaDvoo8h2dAd/d6g334xvCRZ SK2A1lS1pmjvNzTyh+SXigumag== X-Received: by 2002:a17:907:91cd:b0:96a:937c:5608 with SMTP id h13-20020a17090791cd00b0096a937c5608mr9052699ejz.53.1684843198168; Tue, 23 May 2023 04:59:58 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id h26-20020a17090634da00b0096f7e7d1566sm4318582ejb.224.2023.05.23.04.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 04:59:57 -0700 (PDT) References: <20230517200814.3157916-1-aliceryhl@google.com> User-agent: mu4e 1.10.3; emacs 28.2.50 From: Andreas Hindborg To: Alice Ryhl Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , Benno Lossin , Will Deacon , Peter Zijlstra , Mark Rutland , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wedson Almeida Filho Subject: Re: [PATCH v1 1/2] rust: sync: add `Arc::ptr_eq` Date: Tue, 23 May 2023 13:54:19 +0200 In-reply-to: <20230517200814.3157916-1-aliceryhl@google.com> Message-ID: <87353nfebm.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Alice Ryhl writes: > Add a method for comparing whether two `Arc` pointers reference the same > underlying object. > > This comparison can already be done by getting a reference to the inner > values and comparing whether the references have the same address. > However, writing `Arc::ptr_eq(a, b)` is generally less error-prone than > doing the same check on the references, since you might otherwise > accidentally compare the two `&Arc` references instead, which wont > work because those are pointers to pointers to the inner value, when you > just want to compare the pointers to the inner value. > > Also, this method might optimize better because getting a reference to > the inner value involves offsetting the pointer, which this method does > not need to do. > > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Alice Ryhl Reviewed-by: Andreas Hindborg > --- > rust/kernel/sync/arc.rs | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index e6d206242465..274febe3bb06 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -221,6 +221,11 @@ impl Arc { > // reference can be created. > unsafe { ArcBorrow::new(self.ptr) } > } > + > + /// Compare whether two [`Arc`] pointers reference the same underlying object. > + pub fn ptr_eq(this: &Self, other: &Self) -> bool { > + core::ptr::eq(this.ptr.as_ptr(), other.ptr.as_ptr()) > + } > } > > impl ForeignOwnable for Arc { > > base-commit: ac9a78681b921877518763ba0e89202254349d1b