summaryrefslogtreecommitdiff
path: root/src/semaphore.h
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-04-13 18:30:56 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-04-13 18:30:56 +0200
commitfb7bb2ee352cf83a7596a7ed7ba2913a2257e540 (patch)
tree7f45c45563dd13233061d25a96967c4b1e9958c5 /src/semaphore.h
parent057ef1d83ba263fb2adf1aa86f8e281ab0065c43 (diff)
New Semaphore method wait with timeout.
Diffstat (limited to 'src/semaphore.h')
-rw-r--r--src/semaphore.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/semaphore.h b/src/semaphore.h
index 4464898..d5995cb 100644
--- a/src/semaphore.h
+++ b/src/semaphore.h
@@ -24,22 +24,26 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#ifndef __PRACRO_SEMAPHORE_H__
-#define __PRACRO_SEMAPHORE_H__
+#pragma once
+
+#include <chrono>
struct semaphore_private_t;
-class Semaphore {
+class Semaphore
+{
public:
- Semaphore(const char *name = "");
- ~Semaphore();
+ Semaphore(std::size_t initial_count = 0);
+ ~Semaphore();
+
+ void post();
- void post();
- void wait();
+ //! Lock semaphore with timeout.
+ //! \returns true if the semaphore was locked, false on timeout.
+ bool wait(const std::chrono::milliseconds& timeout);
+
+ void wait();
private:
struct semaphore_private_t *prv{nullptr};
- const char *name{nullptr};
};
-
-#endif/*__PRACRO_SEMAPHORE_H__*/