Semaphores
SPDX-License-Identifier: Apache-2.0
The Zephyr RTOS shall provide a mechanism to define and initialize a semaphore at compile time.
The Zephyr RTOS shall provide a mechanism to define and initialize a semaphore at runtime.
The Zephyr RTOS shall define the maximum limit of a semaphore when the semaphore is used for counting purposes and does not have an explicit limit.
When initializing a counting semaphore, the maximum permitted count a semaphore can have shall be set.
When initializing a counting semaphore, the initial semaphore value shall be set.
The Zephyr RTOS shall provide a mechanism allowing threads to acquire a semaphore.
While the semaphore's count is greater than zero, the requesting thread shall acquire the semaphore and decrement its count.
While the semaphore's count is zero, the requesting thread shall be blocked until the semaphore is released by another thread.
When attempting to acquire a semaphore, the Zephyr RTOS shall accept options that specify timeout periods, allowing threads to set a maximum wait time for semaphore acquisition.
When attempting to acquire a semaphore, where the semaphore is not acquired within the specified time, the Zephyr RTOS shall return an error indicating a timeout.
When attempting to acquire a semaphore, where the current count is zero and no timeout time was provided, the Zephyr RTOS shall return an error indicating the semaphore is busy.
The Zephyr RTOS shall provide a mechanism allowing threads to release a semaphore.
The Zephyr RTOS shall increment the semaphore's count upon release.
When there are threads waiting on the semaphore, the highest-priority waiting thread shall be unblocked and acquire the semaphore.
The Zephyr RTOS shall provide a mechanism for threads to check the current count of a semaphore without acquiring it.
The Zephyr RTOS shall provide a mechanism that resets the semaphore count to zero.
When a semaphore is reset, the Zephyr RTOS shall abort all existing acquisitions of the semaphore returning a resource contention error code.
When initializing a counting semaphore, where the maximum permitted count of a semaphore is invalid, then the Zephyr RTOS shall return an error indicating invalid values.