This function indicates to the caller if other threads are waiting for this semaphore. It is assumed that the caller holds the semaphore, though it is not asserted.
To be able to implement this function, a new `waiters_count` field was added to `struct rw_semaphone`.
This counter is incremented and decremented by modified versions of `down_{read,write}()`. Here is what they now do in pseudo code:
if (!try lock) {
waiters_count++;
blocking lock;
waiters_count--;
}
On Linux, they would manage this using a wait list and an internal lock
to protect this list.
`down_{read_write}()` functions are moved to a C file because they are a bit more involved than the simple alias to `sx_*lock()`. `up_{read_write}()` were moved as well to keep them together.
The amdgpu DRM driver started to use `rwsem_is_contended()` in Linux 6.12.
This is part of the [[ https://github.com/freebsd/drm-kmod/pull/427 | update of DRM drivers to Linux 6.12 ]].
Sponsored by: The FreeBSD Foundation