AdsLib
Loading...
Searching...
No Matches
AdsLib
Semaphore.h
1
// SPDX-License-Identifier: MIT
7
#pragma once
8
9
#include <condition_variable>
10
#include <mutex>
11
12
struct
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
27
private
:
28
int
count = 0;
29
std::mutex mutex;
30
std::condition_variable cv;
31
};
Semaphore
Definition:
Semaphore.h:12
Generated on Fri Dec 16 2022 11:37:25 for AdsLib by
1.9.5