git: 0e7c7cfd1127 - main - locks: provide a macro to extract lock_object from various lock types

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Fri, 18 Sep 2026 21:31:51 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=0e7c7cfd11275ac70e1f9ba10ced67a286c89bef

commit 0e7c7cfd11275ac70e1f9ba10ced67a286c89bef
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-09-18 21:13:27 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-09-18 21:14:28 +0000

    locks: provide a macro to extract lock_object from various lock types
    
    To be used in _Generic() KPIs that accept different lock types.
    
    Reviewed by:            kib
    Differential Revision:  https://reviews.freebsd.org/D59455
---
 sys/sys/lock.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index 74e222176b4a..18e88bc0c343 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -161,6 +161,16 @@ struct lock_class {
 
 #define	lock_initialized(lo)	((lo)->lo_flags & LO_INITIALIZED)
 
+/*
+ * The lk2lo() macro is used to extract lock_object from various lock types
+ * that embed lock_object for purpose of writing a _Generic() macro that would
+ * allow to create a single KPI for different kinds of locks.
+ * The NOLOCK is lock-typed NULL pointer, to be used as no-lock argument in
+ * such _Generic() macros.
+ */
+#define	lk2lo(lk)	(&(lk)->lock_object)
+#define	NOLOCK		((struct mtx *)0)
+
 extern struct lock_class lock_class_mtx_sleep;
 extern struct lock_class lock_class_mtx_spin;
 extern struct lock_class lock_class_sx;