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
This commit is contained in:
+11
-1
@@ -24,7 +24,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
.\" DAMAGE.
|
||||
.\"
|
||||
.Dd November 11, 2017
|
||||
.Dd Apri 30, 2026
|
||||
.Dt SX 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -46,6 +46,7 @@
|
||||
.Nm sx_sleep ,
|
||||
.Nm sx_xholder ,
|
||||
.Nm sx_xlocked ,
|
||||
.Nm sx_has_waiters ,
|
||||
.Nm sx_assert ,
|
||||
.Nm SX_SYSINIT ,
|
||||
.Nm SX_SYSINIT_FLAGS
|
||||
@@ -88,6 +89,8 @@
|
||||
.Fn sx_xholder "struct sx *sx"
|
||||
.Ft int
|
||||
.Fn sx_xlocked "const struct sx *sx"
|
||||
.Ft int
|
||||
.Fn sx_has_waiters "const struct sx *sx"
|
||||
.Pp
|
||||
.Cd "options INVARIANTS"
|
||||
.Cd "options INVARIANT_SUPPORT"
|
||||
@@ -268,6 +271,13 @@ is returned instead.
|
||||
will return non-zero if the current thread holds the exclusive lock;
|
||||
otherwise, it will return zero.
|
||||
.Pp
|
||||
.Fn sx_has_waiters
|
||||
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.
|
||||
.Pp
|
||||
For ease of programming,
|
||||
.Fn sx_unlock
|
||||
is provided as a macro frontend to the respective functions,
|
||||
|
||||
Reference in New Issue
Block a user