Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2705983rwd; Wed, 17 May 2023 13:16:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vtn+YlHAbof5m0upPV4NJdph0xH6oPdFE0t0AOoyUoeXLad1A+eHvw7QvbP2KEQlKhD6Z X-Received: by 2002:a05:6a20:841b:b0:107:35ed:28a7 with SMTP id c27-20020a056a20841b00b0010735ed28a7mr7315669pzd.8.1684354609846; Wed, 17 May 2023 13:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684354609; cv=none; d=google.com; s=arc-20160816; b=WFCFZifmJKLXRL80ZroNGQB6mOtKFu3kaiO6ykutVyxQYU87gNI8bvuZ2SjZ0Cqu8e 9TSGMJ9RUbLCWAoLx7yExpnNvQJ2c2CmyJFJ1eNUmO8fjh2zsvOLR19Ab8ENxy/OyUUd KR2IVCcJ0ewaEggp4bNjM7C5TscBqz1rzQpEW2li88DYmlCsh6TvuYXkTXU/u7D1aIhj WYQwpg0uRj9nAWXlKoxFwJXhWIIcL1QozSK4g3VUHh+i6Xs+ZIfclw0hlQx88LGVa2cZ Y+xK9TGAwiIS50WR/5S/TFSfNIuT3WbDHfYsAUErvSrN41DCSj+I/1/YkbYYjDzjT0wc JFEQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020a6566c6000000b005303bf3e14bsi22428267pgw.412.2023.05.17.13.16.34; Wed, 17 May 2023 13:16:49 -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 S229454AbjEQUIg (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=20Roy=20Baron?=" , 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 Content-Type: text/plain; charset="UTF-8" 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 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 --- 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 -- 2.40.1.606.ga4b1b128d6-goog