Messages in this thread | | | From | John Ogness <> | Subject | Re: [PATCH printk v1 11/13] printk: reimplement console_lock for proper kthread support | Date | Fri, 18 Feb 2022 23:09:01 +0106 |
| |
On 2022-02-18, John Ogness <john.ogness@linutronix.de> wrote: >> This is another complexity. An easier solution would be to do: >> >> console_trylock() >> { >> if (down_trylock(&console_sem)) >> return failed; >> >> for_each_console(con) { >> if (mutext_trylock(&con->lock)) >> goto fail; >> } >> >> // sucess >> >> fail: >> for_each_console(con_fail) { >> if (con_fail == con) >> break; >> mutex_unlock(&con->lock); >> } > > No, this cannot work. Semaphores are the _only_ synchonization object in > the kernel that is allowed to perform a trylock from any context > (because they don't have owners).
Sorry, I need to clarify this bold statement.
Semaphores are the only synchonization object in the kernel that is allowed to perform a trylock from any context and does not disable preemption upon locking. (This is important because console lock holders expect preemption to be unaffected when taking the lock.)
John
| |