The mutex API
Posted Jan 12, 2006 9:41 UTC (Thu) by simlo
Parent article: The mutex API
Note that mutex_unlock() cannot be called from interrupt context. This restriction appears to have more to do with keeping mutexes from ever being used as completions than a fundamental restriction caused by the mutex design itself.
If you could it would not be a mutex but a semaphore! A mutex can only be
unlocked by the owner - which must be a task. But when you turn off the debug code, Ingo's mutex is indeed just a binary semaphore.
At computer science we were indeed told to use binary semaphores as mutual exclusion locks. But it is a bad advice. The semantics is very different. To help debugging and make the code more understandable it is really a good idea to use seperate types for completion type semaphores and mutex and to enforce the mutex semantics. On real-time systems you must use a mutex with some kind of priority inversion prevention (priority inheritance or priority ceiling). Therefore it is essential not to mix up mutex with completions on that kind of systems.
Furthermore: When a mutex can't be touched from interrupts, you don't have
to disable interrupts while performing mutex operations.
to post comments)