summaryrefslogtreecommitdiff
path: root/test/semaphore.h
blob: 6a5963f566524bfc34103660011df178f5e35886 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef MYGRATE_TEST_SEMAPHORE_H
#define MYGRATE_TEST_SEMAPHORE_H

#if __has_include(<semaphore>)
#	include <semaphore>
#endif

#ifdef __cpp_lib_semaphore
using semaphore = std::binary_semaphore;
#else
#	include <mutex>
class semaphore {
public:
	explicit semaphore(unsigned int v_);

	void release(unsigned int n = 1);

	void acquire();

private:
	bool try_dec();
	unsigned int v;
	std::mutex m;
};
#endif

#endif