modm API documentation
modm::rtos::Semaphore Class Reference

Counting semaphore. More...

#include <modm/processing/rtos/semaphore.hpp>

Inheritance diagram for modm::rtos::Semaphore:

Public Member Functions

 Semaphore (unsigned portBASE_TYPE max, unsigned portBASE_TYPE initial)
 Create a counting semaphore. More...
 

Detailed Description

Counting semaphore.

Counting semaphores are typically used for two things:

    >
  1. 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.
  2. 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.

Constructor & Destructor Documentation

modm::rtos::Semaphore::Semaphore ( unsigned portBASE_TYPE  max,
unsigned portBASE_TYPE  initial 
)

Create a counting semaphore.

Parameters
maxMaximum count value
initialInitial value

The documentation for this class was generated from the following files: