Re: Wait for mutex to become unlocked

From: Matthew Wilcox
Date: Thu May 05 2022 - 00:13:23 EST


On Thu, May 05, 2022 at 09:52:23AM +0800, Hillf Danton wrote:
> +++ x/kernel/locking/rwsem.c
> @@ -1464,6 +1464,35 @@ void __sched down_read(struct rw_semapho
> }
> EXPORT_SYMBOL(down_read);
>
> +static void __rwsem_wait(struct rw_semaphore *sem, int read, int state)
> +{
> + DEFINE_WAIT(wait);
> + int locked;
> +
> + prepare_to_wait(&sem->willy_wq, &wait, state);
> + if (read)
> + locked = down_read_trylock(sem);

... but then we just acquired the lock. And the point was to never
acquire the lock.

Also, what's the 'willy_wq' thing? Do you mean wait_list?
Oh, no, I see, you're pretending that we should add an extra waitq
to the rwsem. That's very silly.

The point was not to ask "how can we do this", the question was "should we
do this?" And Thomas, at least for now, is saying "No".

If you want to figure out how to do it properly, see rwsem_add_waiter()
and how it's used.