libcamera  v0.0.0+3-3b6e2d50-dirty (2022-01-27T16:18:04+08:00)
Supporting cameras in Linux since 2019
semaphore.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * semaphore.h - General-purpose counting semaphore
6  */
7 #ifndef __LIBCAMERA_BASE_SEMAPHORE_H__
8 #define __LIBCAMERA_BASE_SEMAPHORE_H__
9 
10 #include <condition_variable>
11 
12 #include <libcamera/base/private.h>
13 #include <libcamera/base/thread.h>
14 
15 namespace libcamera {
16 
17 class Semaphore
18 {
19 public:
20  Semaphore(unsigned int n = 0);
21 
22  unsigned int available();
23  void acquire(unsigned int n = 1);
24  bool tryAcquire(unsigned int n = 1);
25  void release(unsigned int n = 1);
26 
27 private:
28  Mutex mutex_;
29  std::condition_variable cv_;
30  unsigned int available_;
31 };
32 
33 } /* namespace libcamera */
34 
35 #endif /* __LIBCAMERA_BASE_SEMAPHORE_H__ */
General-purpose counting semaphore.
Definition: semaphore.h:18
bool tryAcquire(unsigned int n=1)
Try to acquire n resources without blocking.
Definition: semaphore.cpp:75
Semaphore(unsigned int n=0)
Construct a semaphore with n resources.
Definition: semaphore.cpp:34
unsigned int available()
Retrieve the number of available resources.
Definition: semaphore.cpp:43
void acquire(unsigned int n=1)
Acquire n resources.
Definition: semaphore.cpp:57
void release(unsigned int n=1)
Release n resources.
Definition: semaphore.cpp:93
Top-level libcamera namespace.
Definition: bound_method.h:15
std::mutex Mutex
An alias for std::mutex.
Definition: thread.h:29
Thread support.