diff options
Diffstat (limited to 'test/semaphore.cpp')
-rw-r--r-- | test/semaphore.cpp | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/test/semaphore.cpp b/test/semaphore.cpp deleted file mode 100644 index b7e089f..0000000 --- a/test/semaphore.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "semaphore.h" - -#ifndef __cpp_lib_semaphore -# include <thread> - -semaphore::semaphore(unsigned int v_) : v {v_} { } - -void -semaphore::release(unsigned int n) -{ - std::lock_guard lk {m}; - v += n; -} - -void -semaphore::acquire() -{ - while (!try_dec()) { } -} - -bool -semaphore::try_dec() -{ - m.lock(); - if (v) { - v--; - m.unlock(); - return true; - } - else { - m.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - return false; - } -} - -#endif |