From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 199A115531A for ; Wed, 20 Nov 2024 22:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732141682; cv=none; b=dnIMLGHMj6S7x/k0vsOpv90oK3hZbb+Z0BlXt/Pa+bOuWnKxaoy7r/4vA9QqNrQRRMcQMePCD0VEqYZl0XOcFYJWMLYcJI4OQKHljKgpCbyn5i0U+BRGJqn7UsJKe41EAj87c5IpBqo+MG8rQFpNH9QZh88O+UaPx3pfuF7n9XU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732141682; c=relaxed/simple; bh=+lVGu84p1gi7XJweOuTj9nd0/+5uqOqhs1NVKt6TfWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V0D3nH6reUxLMJ4vTh1ONW+AlOOQS/n3ae7HoonscgMoKFhiT8ET2gtZ7rW80FQPe2qfwD17bfN0WnYoLm/mt6rUD2kDJO324v9wPpy32oocUrFcSv3M3JWtOQSkqGKCs48V19S43lDz9+KKYBlxyHdyrjwghZRsKUCVF5ZA7+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fP4QTdyE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fP4QTdyE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732141679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LnF/ASEMLKIeD+1oLAnAGOV+Mp//Bp/l46axBXA2lAs=; b=fP4QTdyEVEiPMhhVebhoAPVkwX7ZbGy+fLz9dQxrAVhPV78BPcikKLPa2ydgASSLYy/19f TeAgrBGaYGLQPMUmwI0IFLZqM+Xyar0rfNAUkp/3lO1Q+kKzI9q4WhyUcW8JoXjuwnYKj5 bohm/Ng//8821fjQ4twlBBFAKVIscfk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-uPc41WsFM0SENU5OA-ue5Q-1; Wed, 20 Nov 2024 17:27:55 -0500 X-MC-Unique: uPc41WsFM0SENU5OA-ue5Q-1 X-Mimecast-MFC-AGG-ID: uPc41WsFM0SENU5OA-ue5Q Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A57701955F3C; Wed, 20 Nov 2024 22:27:53 +0000 (UTC) Received: from chopper.redhat.com (unknown [10.22.88.12]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4470B1956086; Wed, 20 Nov 2024 22:27:50 +0000 (UTC) From: Lyude Paul To: rust-for-linux@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Martin Rodriguez Reboredo , Filipe Xavier , Danilo Krummrich , Wedson Almeida Filho Subject: [PATCH 1/2] rust: sync: Add MutexGuard type alias Date: Wed, 20 Nov 2024 17:26:28 -0500 Message-ID: <20241120222742.2490495-2-lyude@redhat.com> In-Reply-To: <20241120222742.2490495-1-lyude@redhat.com> References: <20241120222742.2490495-1-lyude@redhat.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 A simple helper alias for code that needs to deal with Guard types returned from Mutexes. Signed-off-by: Lyude Paul --- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/mutex.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 2bdd1cffcdab3..0f630714da2aa 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -15,7 +15,7 @@ pub use arc::{Arc, ArcBorrow, UniqueArc}; pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult}; pub use lock::global::{global_lock, GlobalGuard, GlobalLock, GlobalLockBackend, GlobalLockedBy}; -pub use lock::mutex::{new_mutex, Mutex}; +pub use lock::mutex::{new_mutex, Mutex, MutexGuard}; pub use lock::spinlock::{new_spinlock, SpinLock}; pub use locked_by::LockedBy; diff --git a/rust/kernel/sync/lock/mutex.rs b/rust/kernel/sync/lock/mutex.rs index 0e946ebefce12..10a70c07268dc 100644 --- a/rust/kernel/sync/lock/mutex.rs +++ b/rust/kernel/sync/lock/mutex.rs @@ -86,6 +86,14 @@ macro_rules! new_mutex { /// [`struct mutex`]: srctree/include/linux/mutex.h pub type Mutex = super::Lock; +/// A [`Guard`] acquired from locking a [`Mutex`]. +/// +/// This is simply a type alias for a [`Guard`] returned from locking a [`Mutex`]. It will unlock +/// the [`Mutex`] upon being dropped. +/// +/// [`Guard`]: super::Guard +pub type MutexGuard<'a, T> = super::Guard<'a, T, MutexBackend>; + /// A kernel `struct mutex` lock backend. pub struct MutexBackend; -- 2.47.0