Rust-for-linux archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: Wedson Almeida Filho <wedsonaf@gmail.com>,
	Alice Ryhl <aliceryhl@google.com>
Cc: mathys35.gasnier@gmail.com, "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>
Subject: Re: [PATCH v2] rust: locks: Add `get_mut` method to `Lock`
Date: Thu, 15 Feb 2024 20:55:11 +0000	[thread overview]
Message-ID: <ff06ddd4-808a-44fd-9230-f60aa43ec1de@proton.me> (raw)
In-Reply-To: <CANeycqqwGE_eyFSDWkmHCBOMZ6+Ty-XK_hKixMtOYqc9_46j2A@mail.gmail.com>

On 15.02.24 17:50, Wedson Almeida Filho wrote:
> On Mon, 12 Feb 2024 at 11:22, Alice Ryhl <aliceryhl@google.com> wrote:
>>
>> On Mon, Feb 12, 2024 at 3:13 PM Mathys-Gasnier via B4 Relay
>> <devnull+mathys35.gasnier.gmail.com@kernel.org> wrote:
>>> +    /// Gets the data contained in the lock
>>> +    /// Having a mutable reference to the lock guarantees that no other threads have access to the lock.
>>> +    /// Making it safe to get a mutable reference to the lock content.
>>> +    pub fn get_mut(&mut self) -> &mut T {
>>> +        self.data.get_mut()
>>> +    }
>>
>> It's impossible to call this method. You can never have a mutable
>> reference to a Linux mutex because we pin our locks. At most, you can
>> have a Pin<&mut Self>.
> 
> Perhaps you meant to say that it's impossible to call this method
> without unsafe blocks? From a `Pin<&mut T>`, we can call
> `get_unchecked_mut` to get an `&mut T`.

That is the wrong way to design this, since it forces an extra
`unsafe` call. Instead this function's receiver type should be
`self: Pin<&mut Self>`.

-- 
Cheers,
Benno


  reply	other threads:[~2024-02-15 20:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-12 14:13 [PATCH v2] rust: locks: Add `get_mut` method to `Lock` Mathys-Gasnier via B4 Relay
2024-02-12 14:22 ` Alice Ryhl
2024-02-15 16:50   ` Wedson Almeida Filho
2024-02-15 20:55     ` Benno Lossin [this message]
2024-02-15 16:52 ` Wedson Almeida Filho

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=ff06ddd4-808a-44fd-9230-f60aa43ec1de@proton.me \
    --to=benno.lossin@proton.me \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --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 \
    --cc=yakoyoku@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 read-only IMAP folder(s) and NNTP newsgroup(s).