summaryrefslogtreecommitdiff
path: root/libadhocutil/semaphore.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-10-10 18:41:14 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-10-10 18:41:14 +0100
commit7a080c917cc6128d46f3eca94413990cc007669d (patch)
treeb69bcbf2a6208f6e5da145eb3fca299cebe548b8 /libadhocutil/semaphore.h
parentAdd stub header for all header only files (diff)
downloadlibadhocutil-7a080c917cc6128d46f3eca94413990cc007669d.tar.bz2
libadhocutil-7a080c917cc6128d46f3eca94413990cc007669d.tar.xz
libadhocutil-7a080c917cc6128d46f3eca94413990cc007669d.zip
Build with an STL semaphore when available
Diffstat (limited to 'libadhocutil/semaphore.h')
-rw-r--r--libadhocutil/semaphore.h36
1 files changed, 0 insertions, 36 deletions
diff --git a/libadhocutil/semaphore.h b/libadhocutil/semaphore.h
deleted file mode 100644
index 8b03907..0000000
--- a/libadhocutil/semaphore.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef ADHOCUTIL_SEMAPHORE_H
-#define ADHOCUTIL_SEMAPHORE_H
-
-// Borrowed from StackOverflow
-// http://stackoverflow.com/questions/4792449/c0x-has-no-semaphores-how-to-synchronize-threads
-
-#include "visibility.h"
-#include <condition_variable>
-#include <cstddef>
-#include <mutex>
-
-namespace AdHoc {
- /// A portable semaphore with timeout support
- class DLL_PUBLIC Semaphore {
- public:
- /// Construct a new semaphore with optional initial count.
- explicit Semaphore(std::size_t initial = 0);
-
- /// Notify one waiting thread.
- void notify();
- /// Wait for a single count.
- void wait();
- /// Wait for a single count with timeout.
- /// @param ms Timeout in milliseconds.
- bool wait(unsigned int ms);
- /// Free
- [[nodiscard]] std::size_t freeCount() const;
-
- private:
- std::mutex mutex;
- std::condition_variable condition;
- std::size_t count;
- };
-}
-
-#endif