31#include <linux/futex.h>
32#include <sys/syscall.h>
37 static int futex(
int *uaddr,
int futex_op,
int val,
38 const struct timespec *timeout,
int *uaddr2,
int val3) {
39 return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
51 bool wait(
struct timespec *timeout =
nullptr) {
54 if (i.compare_exchange_strong(one, 0, std::memory_order_relaxed,
55 std::memory_order_relaxed)) {
58 auto rc = futex((
int *)&i, FUTEX_WAIT, 0, timeout,
nullptr, 0);
60 if (errno == ETIMEDOUT) {
63 if (errno != EAGAIN) {
72 if (i.compare_exchange_strong(zero, 1, std::memory_order_relaxed,
73 std::memory_order_relaxed)) {
74 if (futex((
int *)&i, FUTEX_WAKE, 1,
nullptr,
nullptr, 0) == -1) {
81 std::atomic<int> i = {0};
Binary semaphore class to be used for thread synchronisation.
Definition binarySemaphore.hpp:48
bool wait(struct timespec *timeout=nullptr)
Definition binarySemaphore.hpp:51
void post()
Definition binarySemaphore.hpp:70
Frame Grabber Camera Base Class definitions.
Definition binarySemaphore.hpp:43