AdsLib
Loading...
Searching...
No Matches
Semaphore.h
1// SPDX-License-Identifier: MIT
7#pragma once
8
9#include <condition_variable>
10#include <mutex>
11
12struct Semaphore {
13 void release()
14 {
15 std::unique_lock<std::mutex> lock(mutex);
16 ++count;
17 cv.notify_one();
18 }
19
20 void acquire()
21 {
22 std::unique_lock<std::mutex> lock(mutex);
23 cv.wait(lock, [&](){return count > 0; });
24 --count;
25 }
26
27private:
28 int count = 0;
29 std::mutex mutex;
30 std::condition_variable cv;
31};
Definition: Semaphore.h:12