diff options
author | Lyude Paul <lyude@redhat.com> | 2024-11-20 02:11:03 +0300 |
---|---|---|
committer | Boqun Feng <boqun.feng@gmail.com> | 2024-12-20 01:04:42 +0300 |
commit | 15abc88057eeec052aefde897df277eca2340ac6 (patch) | |
tree | 7a009439ae9a26aab4467a951a18dd6d1def5a0e /rust/helpers/mutex.c | |
parent | 9793c9bb91f1b05473bb6d4a2323a259ef00ff2e (diff) | |
download | linux-15abc88057eeec052aefde897df277eca2340ac6.tar.xz |
rust: sync: Add Lock::from_raw() for Lock<(), B>
The KMS bindings [1] have a few bindings that require manually acquiring
specific locks before calling certain functions. At the moment though,
the only way of acquiring these locks in bindings is to simply call the
C locking functions directly - since said locks are not initialized on
the Rust side of things.
However - if we add `#[repr(C)]` to `Lock<(), B>`, then given `()` is a
ZST - `Lock<(), B>` becomes equivalent in data layout to its inner
`B::State` type. Since locks in C don't have data explicitly associated
with them anyway, we can take advantage of this to add a
`Lock::from_raw()` function that can translate a raw pointer to
`B::State` into its proper `Lock<(), B>` equivalent. This lets us simply
acquire a reference to the lock in question and work with it like it was
initialized on the Rust side of things, allowing us to use less unsafe
code to implement bindings with lock requirements.
[Boqun: Use "Link:" instead of a URL and format the commit log]
Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patchwork.freedesktop.org/series/131522/ [1]
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20241119231146.2298971-2-lyude@redhat.com
Diffstat (limited to 'rust/helpers/mutex.c')
0 files changed, 0 insertions, 0 deletions