Counting semaphore.
More...
#include <modm/processing/rtos/semaphore.hpp>
|
| Semaphore (unsigned portBASE_TYPE max, unsigned portBASE_TYPE initial) |
| Create a counting semaphore. More...
|
|
Counting semaphore.
Counting semaphores are typically used for two things:
>
- Counting events.
In this usage scenario an event handler will 'release' a semaphore each time an event occurs (incrementing the semaphore count value), and a handler thread will 'acquire' a semaphore each time it processes an event (decrementing the semaphore count value). The count value is therefore the difference between the number of events that have occurred and the number that have been processed. In this case it is desirable for the initial count value to be zero.
- Resource management.
In this usage scenario the count value indicates the number of resources available. To obtain control of a resource a thread must first obtain a semaphore - decrementing the semaphore count value. When the count value reaches zero there are no free resources. When a thread finishes with the resource it 'gives' the semaphore back (release()) - incrementing the semaphore count value. In this case it is desirable for the initial count value to be equal to the maximum count value, indicating that all resources are free.
modm::rtos::Semaphore::Semaphore |
( |
unsigned portBASE_TYPE |
max, |
|
|
unsigned portBASE_TYPE |
initial |
|
) |
| |
Create a counting semaphore.
- Parameters
-
max | Maximum count value |
initial | Initial value |
The documentation for this class was generated from the following files:
- rtos/semaphore.hpp
- semaphore.cpp