Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4301614rwl; Wed, 28 Dec 2022 02:06:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXuHoadbb33dlbBwpL7gdsE8GxtGIlht45FddaO1/08lDSCsR46c5j2aPKs2Fy9bM7ljsye+ X-Received: by 2002:a17:906:281b:b0:7c1:5863:f8c4 with SMTP id r27-20020a170906281b00b007c15863f8c4mr20081251ejc.21.1672221992173; Wed, 28 Dec 2022 02:06:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672221992; cv=none; d=google.com; s=arc-20160816; b=VOLsIao8TOKodomPRq5YBwNnbSF9eBAlgPzE7heDzle8Z6JWi0w7YpT83avvsoMyVk gVd5JxNog5XHEBw0vF6MOOZjNunUJhNp+vrpFTy6DK12vaLOXO7Bd1s2af9FkIXp2zMV Kwy2BP9Uf6ei3WLmLybRo8Cr0Kz91apFIR2b3R7VetE7WsAC8bvk0rvEHDQyIj6dKdZ+ WDXxu18dZ3+KyCOR02eG1jGNGYMoFwlYR7zBu4MkDbPPuvPgmneJNWqK7jo6AGdh9TQ2 s1VnXejaAvILXtegXhAKpFq35jRYqTAjShq3Hd23lhdc8aXnczNS3nsLYlcKy49DDdTP Z3HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:feedback-id:dkim-signature :dkim-signature; bh=zJ9H10w8qH7GxLiJRMvCYl4baqrj5iP/EW2fYSs9PSs=; b=NsQSSawkLgnB8KSibAV/Nf4XlqGEbhh7mt2lzu5XXpWp950ZdWvVizXcg+ItHIbriT PcLsRGMcN64og6eAd7gRpfqP7nWadBGTo9hJTMBMCZkPihlx0OlGU4Ypj+QJ4UvDDAfG q/ZVep4riCt0DSvey3BKmBNoJbboCy1DkBJ3TLIxI48TQ0UASCJoxwPX4se4vB1cy4r3 lfQ+WprlIK8JH0mqIeAt4TXqijlCf0JJSPjBhGgqs2eNkF1kQBONsyloz/NL11YeDZof Dr3G0WKwdi8z4OrzUtS46FwkEPS8kXTlj+NYiWWrA6GBBQ2QHljfVxsme82rSVPBQoTs N2EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=aKUHWAmr; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="Z5qw//C0"; 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=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he7-20020a1709073d8700b007da4fe085d4si14544443ejc.694.2022.12.28.02.06.15; Wed, 28 Dec 2022 02:06:32 -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=@ryhl.io header.s=fm2 header.b=aKUHWAmr; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="Z5qw//C0"; 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=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232655AbiL1KCO (ORCPT + 64 others); Wed, 28 Dec 2022 05:02:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232617AbiL1KCK (ORCPT ); Wed, 28 Dec 2022 05:02:10 -0500 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C095B97; Wed, 28 Dec 2022 02:02:09 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 38E795C00C3; Wed, 28 Dec 2022 05:02:09 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 28 Dec 2022 05:02:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1672221729; x= 1672308129; bh=zJ9H10w8qH7GxLiJRMvCYl4baqrj5iP/EW2fYSs9PSs=; b=a KUHWAmr7o2bzQngALX/NHEuntIkv1PPeQDCFhsjfa2t8mBAngQJSzZLFxxSquQSp jnzulQWKjDAMvkpujaqrIR3bFSlHrQzzerIIz3oduqoMxMDC/l1oneqqagVDYJjI dD/zVguOfoYNoJotAGwCWdnLV98JZiZjZraUoUd+dI1DV3HSf4OzSGWhHvpaMBdN TQGlWk5M0Ke49ZaQ/SdrGjJ9t5U9NiMIVPjqyHRjp32w0rZVLmf2ITP4uHNYULU/ 4MdGFBe+XuBB2/8RuMZO9r55MAH8yw5D07g43TIIBz7aZ7lTIiXt32l/qZkWYa8G AzMnf2gV7lkLL05dr3t8g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1672221729; x= 1672308129; bh=zJ9H10w8qH7GxLiJRMvCYl4baqrj5iP/EW2fYSs9PSs=; b=Z 5qw//C08QpwpXq9liGB0BlM3E4+52CPMNN1nbTDwqVevOwJl3Vuk1D5QZ7yhaNRD SzyHMYUJoeGL/9UZQQX7MoIRRvw1or+2LX4xeZP0/YUop/tqbch2/LVh6OsPBD6c 1+HMvQ25nR1oZJncMyXxsC+1wdrnlSFyHxt9WdU7oQPBARfr1LRhENUv2Kk/W+7p SCCfJh/VO+5l/JclVed2f32xe00GZKiZ8T8B9dgO25PU28vt7dyxSGrpmMdH+JC0 +uP7t2zB30T7Mh8NJrTFAkCDnoaVpeBoUBrXCm5SWpcHnt55dH/b/Tw1yd1YXXbQ sodilPgoAzjGcpsAACOBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedvgdduudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfhuffvvehfjggtgfesthejredttdefjeenucfhrhhomheptehlihgt vgcutfihhhhluceorghlihgtvgesrhihhhhlrdhioheqnecuggftrfgrthhtvghrnhephf ehueeileevjeefkeetvdffveffudeuhffgtedvuefgiefgiedvjeegvdejleejnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlihgtvgesrh ihhhhlrdhioh X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 05:02:07 -0500 (EST) Message-ID: Date: Wed, 28 Dec 2022 11:03:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 From: Alice Ryhl Subject: Re: [PATCH 2/7] rust: sync: allow type of `self` to be `Arc` or variants To: Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , linux-kernel@vger.kernel.org References: <20221228060346.352362-1-wedsonaf@gmail.com> <20221228060346.352362-2-wedsonaf@gmail.com> Content-Language: en-US In-Reply-To: <20221228060346.352362-2-wedsonaf@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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: Alice Ryhl On 12/28/22 07:03, 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)] > > // Ensure conditional compilation based on the kernel configuration works; > // 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::NonNull}; > /// > /// // The refcount drops to zero when `cloned` goes out of scope, and the 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 = 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, > } > > +// This is to allow [`Arc`] (and variants) to be used as the type of `self`. > +impl core::ops::Receiver for Arc {} > + > // SAFETY: It is safe to send `Arc` to another thread when the underlying `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 ultimately access `T` directly, for