From eebb643bb3799ae90dd248f0b5047ec481b26f68 Mon Sep 17 00:00:00 2001 From: Jean-Sébastien Pédron Date: Sun, 12 Apr 2026 19:20:25 +0200 Subject: sx: Add `sx_has_waiters()` macro This macro will return non-zero if there are threads waiting for this lock; otherwise, it will return zero. The function assumes (but does not assert) that the caller already holds the lock and that it is interested in other threads waiting for it to release the lock. The motivation to add this is the implementation of `rwsem_is_contended()` in linuxkpi. This Linux function indicates the same thing to the caller: if other threads are waiting for this semaphore. The amdgpu DRM driver started to use `rwsem_is_contended()` in Linux 6.12. Reviewed by: bz, olce Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56443 --- sys/compat/linuxkpi/common/include/linux/rwsem.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sys/compat') diff --git a/sys/compat/linuxkpi/common/include/linux/rwsem.h b/sys/compat/linuxkpi/common/include/linux/rwsem.h index b7a800b12e18..43688ab93796 100644 --- a/sys/compat/linuxkpi/common/include/linux/rwsem.h +++ b/sys/compat/linuxkpi/common/include/linux/rwsem.h @@ -51,6 +51,7 @@ struct rw_semaphore { #define down_read_nested(_rw, _sc) down_read(_rw) #define init_rwsem(_rw) linux_init_rwsem(_rw, rwsem_name("lnxrwsem")) #define down_write_nest_lock(sem, _rw) down_write(_rw) +#define rwsem_is_contended(_rw) sx_has_waiters(&(_rw)->sx); #ifdef WITNESS_ALL /* NOTE: the maximum WITNESS name is 64 chars */ -- cgit v1.3