rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
To: "Mathys Gasnier" <mathys35.gasnier@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: locks: Add `get_mut` method to `Lock`
Date: Fri, 9 Feb 2024 16:27:38 -0300	[thread overview]
Message-ID: <45395395-9bbe-4ee8-9a4f-f1890cd85752@gmail.com> (raw)
In-Reply-To: <20240209-rust-locks-get-mut-v1-1-ce351fc3de47@gmail.com>

On 2/9/24 13:22, Mathys-Gasnier wrote:
> From: Mathys-Gasnier <mathys35.gasnier@gmail.com>
> 
> Having a mutable reference guarantees that no other threads have
> access to the lock, so we can take advantage of that to grant callers
> access to the protected data without the the cost of acquiring and
> releasing the locks. Since the lifetime of the data is tied to the
> mutable reference, the borrow checker guarantees that the usage is safe.
> 
> Signed-off-by: Mathys-Gasnier <mathys35.gasnier@gmail.com>
> ---
> [...]
> +    /// Gets the data contained in the lock

I wish that this doc comment mentioned what you've said about having a
mutable reference avoids locking, much like the documentation on
`std::sync::Mutex::get_mut`. If you do so then you can add my reviewed.

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>

> +    pub fn get_mut(&mut self) -> &mut T {
> +        self.data.get_mut()
> +    }
>   }
> [...]

  reply	other threads:[~2024-02-09 19:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 16:22 [PATCH] rust: locks: Add `get_mut` method to `Lock` Mathys-Gasnier via B4 Relay
2024-02-09 19:27 ` Martin Rodriguez Reboredo [this message]
2024-02-09 19:44 ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45395395-9bbe-4ee8-9a4f-f1890cd85752@gmail.com \
    --to=yakoyoku@gmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathys35.gasnier@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).