Loading...
Searching...
No Matches
semaphore.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* General-purpose counting semaphore
*/
#pragma once
#include <libcamera/base/private.h>
#include <libcamera/base/mutex.h>
namespace libcamera {
class Semaphore
{
public:
Semaphore(unsigned int n = 0);
unsigned int available() LIBCAMERA_TSA_EXCLUDES(mutex_);
void acquire(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_);
bool tryAcquire(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_);
void release(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_);
private:
Mutex mutex_;
ConditionVariable cv_;
unsigned int available_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
};
} /* namespace libcamera */
libcamera::ConditionVariable
std::condition_variable wrapper integrating with MutexLocker
Definition mutex.h:122
libcamera::Mutex
std::mutex wrapper with clang thread safety annotation
Definition mutex.h:114
libcamera::Semaphore::release
void release(unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_)
Release n resources.
Definition semaphore.cpp:94
libcamera::Semaphore::acquire
void acquire(unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_)
Acquire n resources.
Definition semaphore.cpp:56
libcamera::Semaphore::available
unsigned int available() LIBCAMERA_TSA_EXCLUDES(mutex_)
Retrieve the number of available resources.
Definition semaphore.cpp:42
libcamera::Semaphore::Semaphore
Semaphore(unsigned int n=0)
Construct a semaphore with n resources.
Definition semaphore.cpp:33
libcamera::Semaphore::tryAcquire
bool tryAcquire(unsigned int n=1) LIBCAMERA_TSA_EXCLUDES(mutex_)
Try to acquire n resources without blocking.
Definition semaphore.cpp:76
mutex.h
Mutex classes with clang thread safety annotation.
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17