From 6b9fdc6ad3ac84cf8b8543b6e46b0ca8c4d61860 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 31 Jul 2021 17:14:21 +0100 Subject: Build a basic hacky semaphore for compilers that don't support std::binary_semaphore yet --- test/semaphore.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/semaphore.h (limited to 'test/semaphore.h') diff --git a/test/semaphore.h b/test/semaphore.h new file mode 100644 index 0000000..f2e9355 --- /dev/null +++ b/test/semaphore.h @@ -0,0 +1,27 @@ +#ifndef MYGRATE_TEST_SEMAPHORE_H +#define MYGRATE_TEST_SEMAPHORE_H + +#if __has_include() +# include +#endif + +#ifdef __cpp_lib_semaphore +using semaphore = std::binary_semaphore; +#else +# include +class semaphore { +public: + semaphore(unsigned int v_); + + void release(unsigned int n = 1); + + void acquire(); + +private: + bool try_dec(); + unsigned int v; + std::mutex m; +}; +#endif + +#endif -- cgit v1.2.3