Loading...
Searching...
No Matches
libcamera::Semaphore Class Reference

General-purpose counting semaphore. More...

## Public Member Functions

| Semaphore (unsigned int n=0)
| Construct a semaphore with n resources.
unsigned int | available () LIBCAMERA_TSA_EXCLUDES(mutex_)
| Retrieve the number of available resources.
void | acquire (unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_)
| Acquire n resources.
bool | tryAcquire (unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_)
| Try to acquire n resources without blocking.
void | release (unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_)
| Release n resources.

## Detailed Description

General-purpose counting semaphore.

A semaphore is a locking primitive that protects resources. It is created with an initial number of resources (which may be 0), and offers two primitives to acquire and release resources. The acquire() function tries to acquire a number of resources, and blocks if not enough resources are available until they get released. The release() function releases a number of resources, waking up any consumer blocked on an acquire() call.

## Constructor & Destructor Documentation

## Semaphore()

libcamera::Semaphore::Semaphore | ( | unsigned int | n = 0 | ) |

Construct a semaphore with n resources.

Parameters

  [in] | n | The resource count

## Member Function Documentation

## acquire()

void libcamera::Semaphore::acquire | ( | unsigned int | n = 1 | ) |

Acquire n resources.

Parameters

  [in] | n | The resource count

This function attempts to acquire n resources. If n is higher than the number of available resources, the call will block until enough resources become available.

## available()

unsigned int libcamera::Semaphore::available | ( |  | ) |

Retrieve the number of available resources.

Returns
  The number of available resources

## release()

void libcamera::Semaphore::release | ( | unsigned int | n = 1 | ) |

Release n resources.

Parameters

  [in] | n | The resource count

This function releases n resources, increasing the available resource count by n. If the number of available resources becomes large enough for any consumer blocked on an acquire() call, those consumers get woken up.

## tryAcquire()

bool libcamera::Semaphore::tryAcquire | ( | unsigned int | n = 1 | ) |

Try to acquire n resources without blocking.

Parameters

  [in] | n | The resource count

This function attempts to acquire n resources. If n is higher than the number of available resources, it returns false immediately without acquiring any resource. Otherwise it acquires the resources and returns true.

Returns
  True if the resources have been acquired, false otherwise

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

- include/libcamera/base/semaphore.h
- src/libcamera/base/semaphore.cpp