libcamera
v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
|
General-purpose counting semaphore. More...
Public Member Functions | |
Semaphore (unsigned int n=0) | |
Construct a semaphore with n resources. More... | |
unsigned int | available () LIBCAMERA_TSA_EXCLUDES(mutex_) |
Retrieve the number of available resources. More... | |
void | acquire (unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_) |
Acquire n resources. More... | |
bool | tryAcquire (unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_) |
Try to acquire n resources without blocking. More... | |
void | release (unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_) |
Release n resources. More... | |
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.
libcamera::Semaphore::Semaphore | ( | unsigned int | n = 0 | ) |
Construct a semaphore with n resources.
[in] | n | The resource count |
void libcamera::Semaphore::acquire | ( | unsigned int | n = 1 | ) |
Acquire n resources.
[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.
unsigned int libcamera::Semaphore::available | ( | ) |
Retrieve the number of available resources.
void libcamera::Semaphore::release | ( | unsigned int | n = 1 | ) |
Release n resources.
[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.
bool libcamera::Semaphore::tryAcquire | ( | unsigned int | n = 1 | ) |
Try to acquire n resources without blocking.
[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.