Mutex
SPDX-License-Identifier: Apache-2.0
The Zephyr RTOS shall provide a mutex that allows threads to obtain mutually exclusive access to a shared resource.
As a Zephyr RTOS user I want to be able to synchronize threads when accessing common resources, where the thread shall have the option to: - wait indefinitely until the resource becomes available. - immediately return with an error if the resource is not available and continue. - wait for a given time for the resource to become available or return with an error.
The Zephyr RTOS shall provide a mechanism to define and initialize a mutex at compile time.
The Zephyr RTOS shall provide a mechanism to initialize a mutex at run time.
The Zephyr RTOS shall provide a mechanism for a thread to lock a mutex and become its owner.
While a mutex is not owned by any thread, a thread that locks it shall acquire ownership of the mutex.
While a mutex is owned by another thread, a thread that attempts to lock it shall be blocked until the mutex becomes available or the specified timeout elapses.
When locking a mutex, the Zephyr RTOS shall accept a timeout that specifies the maximum time to wait for the mutex to become available.
When a mutex does not become available within the specified time, the Zephyr RTOS shall return an error indicating that the mutex was not locked.
While a thread owns a mutex, the Zephyr RTOS shall allow that thread to lock the same mutex again, and shall require the thread to unlock it the same number of times before it is released.
The Zephyr RTOS shall provide a mechanism for the owning thread to unlock a mutex.
If a thread that does not own a mutex attempts to unlock it, then the Zephyr RTOS shall return an error and shall not release the mutex.
While a higher-priority thread is blocked waiting on a mutex, the Zephyr RTOS shall raise the priority of the owning thread to that of the highest-priority waiting thread until the mutex is released.