From patchwork Wed May 17 20:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 95530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp28541vqo; Wed, 17 May 2023 13:17:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6tXeCtZzsIIlzClqDQDSywXqyW2t4ROCQX8077v5ZZeVh2VBOFZATn363idHi+IIPZfKci X-Received: by 2002:a17:903:483:b0:1ab:197d:2de1 with SMTP id jj3-20020a170903048300b001ab197d2de1mr86046plb.2.1684354619803; Wed, 17 May 2023 13:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684354619; cv=none; d=google.com; s=arc-20160816; b=i7BerRq6pUrM4YAyaOGNO9KcimR0GQQ+hnA5Ki80YZn7fkOig3PS8xuPbz30UWGi3z xiI6K8FOdeu4SsL8EaqIEwmYGAo1LwysL7CpC7ckx+YiVSOXeht6MOHrLTeVab2oaNhr KaeGmVMS/GnKZlsfg1UEhvFOIoZZ5f8JHj5jwWm/A8z+x/dFnxEuJVXfu4p7uqq75AGH 6JW7Ru/WAWkl9CAdur3w7HD+SRvLDbnHEtpRWCGpMnchc6R8OW1JPa7HooZ3bL0jfPR0 ZclYjEaK1IgOH5mgClKQfDcMU8rm3BNlV3z48t1DTRMe+bLEiDtkQpcQ3524zIGZLN4Q nVbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=WVkaYtQTj8iUhQoCH4E7KYFvPTbFMzSMw0B5Ujo6j7U=; b=MuOq+NBZhVhNOc0XY3cUX2+9LWiiUCR1cF41OAnccVSNS/4UdEQBFCmFMVPqzZkvvs Uo2cWypYTNsFjwGw+Ubn6LkNXvlOC6h8F5xCuUoiSFm7xsWrKzJgU7KTqKpwDi9VYqUI dVkt6gsCkktMMf0LkvKPE6lb7oHJb3Woj5cJY2jqkZUt2xNUh49UJoco4/X7fx/6tM8+ LyVfkFFM1VUB6R6MgEEWajrmYwqAwd+syTj5MG6K8a98X0/tYan808xvKmSbDh6KLq+O EARbAcxz90woTpMUtdseH7AXJOpAfLhgcEUvsldReGHoeuOjfCLdWEoUWnuqjuPk7n64 o82g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="k/7Al0At"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a17090311c900b001ac83d2b070si10650108plh.334.2023.05.17.13.16.34; Wed, 17 May 2023 13:16:59 -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=@google.com header.s=20221208 header.b="k/7Al0At"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229532AbjEQUIg (ORCPT + 99 others); Wed, 17 May 2023 16:08:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjEQUIf (ORCPT ); Wed, 17 May 2023 16:08:35 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE85C659B for ; Wed, 17 May 2023 13:08:33 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id 4fb4d7f45d1cf-50d88a986afso1474247a12.0 for ; Wed, 17 May 2023 13:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684354112; x=1686946112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=WVkaYtQTj8iUhQoCH4E7KYFvPTbFMzSMw0B5Ujo6j7U=; b=k/7Al0AtAF6zKhw0lzSRawbRH6pCbg1kV1kmPFxrNcXxZZYRNvdWDqo5+Or3482dNP c5fXAAOIyOdgdQnsxZsnHrrdaSSFW6pS6MFD9QS3xPcTs7/2pKsMhqtcbzr7t9NAWTNt /l5t3O8F+7nfkfHvCAVmULq94St6KRSnCzLp/wtq0RI1lvTJjYjREhVebxAfmpX790tX bE9vFcQaAVvXxAKahSHmzirCs6T7b2PFBDoJfqyJbxUIb8VJgU/B6rWmDJUfZZ0Z+9iZ 6HIcs8qwMqxTNOhL9TeOLNkASwPfLLroCSB02PAeXZL/qmNASCFOEbmYw9mQZCnFAedm d/Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684354112; x=1686946112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WVkaYtQTj8iUhQoCH4E7KYFvPTbFMzSMw0B5Ujo6j7U=; b=R0c4/mFJQUbOGZtFQLsKrc1+P/nURVZeR+6wKbDVTIhO39pNTkGmVkBc65XzkraYDU KzarpEsntX8zLnyOleLjqel8raSlD1SCAgFdmH01DEGMbm51zIsYkWoesvqVA65//CII VNGzGSh3HXdT+s+uqc7Q+zOU1/GlMLeTBtM23LOnd0obqIwMcR/GDQxIMUezf4KDWlDR 8Wryxq26HQ8TBIm/UVOck5SHooj/qERUeIKJfAw4uoSnZBgAvWNYo6Cs5QZMazt7ElHW yQExGzcxFv60oICCP0R6HvRYeppKh8WA25a0a68os46pbUelC7Mt1m4Q+mYZcIS6TstL gk7A== X-Gm-Message-State: AC+VfDxYy3I5mFNYWKgdr4LL59jMt2oYi2u35dI1bjYkFZwhquIG3UWE S1XYgo2ky1s4KWh6h0qJGwvrlDu3sPgKhCw= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a50:aac5:0:b0:510:b4dc:1656 with SMTP id r5-20020a50aac5000000b00510b4dc1656mr1476722edc.3.1684354112325; Wed, 17 May 2023 13:08:32 -0700 (PDT) Date: Wed, 17 May 2023 20:08:13 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230517200814.3157916-1-aliceryhl@google.com> Subject: [PATCH v1 1/2] rust: sync: add `Arc::ptr_eq` From: Alice Ryhl To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Will Deacon , Peter Zijlstra , Mark Rutland , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wedson Almeida Filho X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766173829447309222?= X-GMAIL-MSGID: =?utf-8?q?1766173829447309222?= 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: Martin Rodriguez Reboredo Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Reviewed-by: Benno Lossin --- rust/kernel/sync/arc.rs | 5 +++++ 1 file changed, 5 insertions(+) base-commit: ac9a78681b921877518763ba0e89202254349d1b 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 {