[PATCH 2/3] rust: task: implement == operator for Task

Alice Ryhl posted 3 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 2/3] rust: task: implement == operator for Task
Posted by Alice Ryhl 1 month, 1 week ago
It's useful to compare if two tasks are the same task or not. Rust
Binder wants this to check if a certain task is equal to the group
leader of current.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/task.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
index cc907fb531bceea6e8dc1175d9350bd24780a3d5..8834bf25cce5e7b7f48cd649c977eb92fbfb61e9 100644
--- a/rust/kernel/task.rs
+++ b/rust/kernel/task.rs
@@ -362,6 +362,14 @@ unsafe fn dec_ref(obj: ptr::NonNull<Self>) {
     }
 }
 
+impl PartialEq for Task {
+    fn eq(&self, other: &Self) -> bool {
+        ptr::eq(self.as_ptr(), other.as_ptr())
+    }
+}
+
+impl Eq for Task {}
+
 impl Kuid {
     /// Get the current euid.
     #[inline]

-- 
2.53.0.335.g19a08e0c02-goog
Re: [PATCH 2/3] rust: task: implement == operator for Task
Posted by Gary Guo 1 month, 1 week ago
On 2026-02-19 13:52, Alice Ryhl wrote:
> It's useful to compare if two tasks are the same task or not. Rust
> Binder wants this to check if a certain task is equal to the group
> leader of current.
> 
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>  rust/kernel/task.rs | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> index 
> cc907fb531bceea6e8dc1175d9350bd24780a3d5..8834bf25cce5e7b7f48cd649c977eb92fbfb61e9 
> 100644
> --- a/rust/kernel/task.rs
> +++ b/rust/kernel/task.rs
> @@ -362,6 +362,14 @@ unsafe fn dec_ref(obj: ptr::NonNull<Self>) {
>      }
>  }
> 
> +impl PartialEq for Task {

Missing `#[inline]`. With this fixed:

Reviewed-by: Gary Guo <gary@garyguo.net>

> +    fn eq(&self, other: &Self) -> bool {
> +        ptr::eq(self.as_ptr(), other.as_ptr())
> +    }
> +}
> +
> +impl Eq for Task {}
> +
>  impl Kuid {
>      /// Get the current euid.
>      #[inline]