// SPDX-License-Identifier: MIT
/**
Copyright (c) 2015 -2020 Beckhoff Automation GmbH & Co. KG
Author: Patrick Bruenn
*/
#pragma once
#include
#include
struct Semaphore {
void release()
{
std::unique_lock lock(mutex);
++count;
cv.notify_one();
}
void acquire()
{
std::unique_lock lock(mutex);
cv.wait(lock, [&](){return count > 0; });
--count;
}
private:
int count = 0;
std::mutex mutex;
std::condition_variable cv;
};