Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp13456747rwl; Wed, 4 Jan 2023 08:24:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXusnTpa/cdMVRcYmrNxrCK/F+ahxOL2nxaQ5sspkUuSI90U8fzqPpCIueI698Roh0KJJxty X-Received: by 2002:a17:907:8b12:b0:78d:f457:1062 with SMTP id sz18-20020a1709078b1200b0078df4571062mr41362447ejc.31.1672849440903; Wed, 04 Jan 2023 08:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672849440; cv=none; d=google.com; s=arc-20160816; b=ceEux95vhiUj33D62JRBdRuMssLbzxI475rMZsaTx9W0qTI0xixzAbpBQHJbpp1lmu QGVkFpYQExkd7hOI3Lck6ohTSfp6jz/lIWt1geNPY+wsnr8oFJAh3faqRVqK0eZcv0/z bvRpVbXuJFK3RFbWXYYosA20QG8Lw13t+W7g+/Bbgo5YvkiThaCW4pp7xZo7C0znQ+bB Vd9pdYC0kGph17lTmIdZWU1ttRiHlmdvneSMgdSpCGwD+teYyDPD9+HGyU4hd98kC23g XIzWZhkbhWanfzQSwA5z4mbJKiJ7SsHM+dnO05FZ+/EAQ44Qys5NCZpul9vWTQQyGaow ME+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:from:subject:cc:to :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=9Hlvv2tc0F9GFZmQLiemf82atd7u3rSszUw1WF2uBwc=; b=KH4hiUaD7cNj0UDUehEUj6PAhOwQ9zSCyWnQb78vZsVU0XZyflitTuMrfXCyaJAJN1 szguKGt5xdri0Ph9DNcfrH2B7r+dW+/M9/uroMHqj/xLU9eVRB9UCZGOUifdJ5gKW85f EJTXlbpN4LMyDDtR4pVBRLklK+nc0Oxi540YgMKG9+UTAMx7I7g3BmvEVtfcpbKHISvd RDw54xyZDKCJcqsL8iDc65mMxzlnfRSOQuavGesxqGBqKD6MxiDfiz1H7Nr0XvHWy8ML Pz/3ICG4RVwqfXltUtEH9RORauLs03TEFkxauOL8rte1p3wIamofGM7SQJTEP0YTsIrC eWkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SlVpJckn; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr9-20020a1709073f8900b0078223ff2756si33656653ejc.244.2023.01.04.08.23.47; Wed, 04 Jan 2023 08:24:00 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=SlVpJckn; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235156AbjADQNT (ORCPT + 57 others); Wed, 4 Jan 2023 11:13:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239451AbjADQMT (ORCPT ); Wed, 4 Jan 2023 11:12:19 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7324F26E8; Wed, 4 Jan 2023 08:12:04 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id i15so49294210edf.2; Wed, 04 Jan 2023 08:12:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9Hlvv2tc0F9GFZmQLiemf82atd7u3rSszUw1WF2uBwc=; b=SlVpJcknrODgQBazYB40N0B0/ZOgkZhuTJwDUmcttV6IrHpP83dkyXRxcAOKqciv8L FZicATQiPNly+oNlvEYTj0DXzhHWua1hRUrD6Li3A0DBNekyagw79hFDS7uY/6dRYHPw no6xTYUAdazMheCKy2EWrpft/ENfqBLRveWDAYMp1AuFvEGwo7OQ+Id1uC66Q8TwnMMH 2qEIZbT0ldTyHzY501ehBzha8xxOjl122/rBgsYWVj+3kMR9Rsia/7Nyo667CFZpFp8F jn/L7r6K04Bx3WWtnwGO6uF7h8IOlsU2/9WGErqla1gsHVflfV1PZGg6x2NRt8X71jSm 328g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=9Hlvv2tc0F9GFZmQLiemf82atd7u3rSszUw1WF2uBwc=; b=3AJaLLaxA7no7h7rxABmXgKlqSz89VoqJznaAaBY/wOItzg+qDywNz93SeS8mw46+d 2dBCRGYxV7dmKiK2boCYPSpuHGAgDNFU9/bBEkkeIrMnVW374T2HoQ4iKR4o1ifwoPzW yx5fWr5ULH0EkHHlrE6N0hi893AIo8pwR9zor76AjRx7HUcwFq1iCFm9YX8QK/FXhbRJ PFsEJ2uiS3iYomGY1JoYOJx/wVtw+pcP+PPfonHzLx2xebF5F4z6fgCDcxKUO9WapqkR JRX4AviJsvM9NTzYWxf+fuMRhoR6+7O4/qa8z26WiOLqUPZ+8UfufD2HOdWGwJ/+mV3m kn/Q== X-Gm-Message-State: AFqh2kqdLSlHaFA6vPvoyWQJaRbdY0oWmJwyPudm9MLpGb3YlKVMux3m 6V2OTZ+UY5MesxptHtA+/MKH9glrSJUYGHVfjILuVh/+ X-Received: by 2002:a05:6402:541a:b0:46c:6ed1:83b0 with SMTP id ev26-20020a056402541a00b0046c6ed183b0mr42542184edb.9.1672848723061; Wed, 04 Jan 2023 08:12:03 -0800 (PST) Received: from localhost (host-82-60-200-213.retail.telecomitalia.it. [82.60.200.213]) by smtp.gmail.com with ESMTPSA id d24-20020a50fb18000000b004615f7495e0sm14929712edq.8.2023.01.04.08.12.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Jan 2023 08:12:02 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 04 Jan 2023 17:12:00 +0100 Message-Id: To: "Wedson Almeida Filho" , Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Subject: Re: [PATCH 2/7] rust: sync: allow type of `self` to be `Arc` or variants From: "Vincenzo" X-Mailer: aerc 0.8.2 References: <20221228060346.352362-1-wedsonaf@gmail.com> <20221228060346.352362-2-wedsonaf@gmail.com> In-Reply-To: <20221228060346.352362-2-wedsonaf@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Reviewed-by: Vincenzo Palazzo On Wed Dec 28, 2022 at 7:03 AM CET, Wedson Almeida Filho wrote: > This allows associated functions whose `self` argument has `Arc` or > variants as their type. This, in turn, allows callers to use the dot > syntax to make calls. > > Signed-off-by: Wedson Almeida Filho > --- > rust/kernel/lib.rs | 1 + > rust/kernel/sync/arc.rs | 28 ++++++++++++++++++++++++++++ > 2 files changed, 29 insertions(+) > > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index ace064a3702a..1a10f7c0ddd9 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -14,6 +14,7 @@ > #![no_std] > #![feature(allocator_api)] > #![feature(core_ffi_c)] > +#![feature(receiver_trait)] > =20 > // Ensure conditional compilation based on the kernel configuration work= s; > // otherwise we may silently break things like initcall handling. > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index 22290eb5ab9b..e2eb0e67d483 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -57,6 +57,31 @@ use core::{marker::PhantomData, ops::Deref, ptr::NonNu= ll}; > /// > /// // The refcount drops to zero when `cloned` goes out of scope, and t= he memory is freed. > /// ``` > +/// > +/// Using `Arc` as the type of `self`: > +/// > +/// ``` > +/// use kernel::sync::Arc; > +/// > +/// struct Example { > +/// a: u32, > +/// b: u32, > +/// } > +/// > +/// impl Example { > +/// fn take_over(self: Arc) { > +/// // ... > +/// } > +/// > +/// fn use_reference(self: &Arc) { > +/// // ... > +/// } > +/// } > +/// > +/// let obj =3D Arc::try_new(Example { a: 10, b: 20 })?; > +/// obj.use_reference(); > +/// obj.take_over(); > +/// ``` > pub struct Arc { > ptr: NonNull>, > _p: PhantomData>, > @@ -68,6 +93,9 @@ struct ArcInner { > data: T, > } > =20 > +// This is to allow [`Arc`] (and variants) to be used as the type of `se= lf`. > +impl core::ops::Receiver for Arc {} > + > // SAFETY: It is safe to send `Arc` to another thread when the underl= ying `T` is `Sync` because > // it effectively means sharing `&T` (which is safe because `T` is `Sync= `); additionally, it needs > // `T` to be `Send` because any thread that has an `Arc` may ultimate= ly access `T` directly, for > --=20 > 2.34.1