From fb7bb2ee352cf83a7596a7ed7ba2913a2257e540 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 13 Apr 2016 18:30:56 +0200 Subject: New Semaphore method wait with timeout. --- src/semaphore.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/semaphore.h') 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 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__*/ -- cgit v1.2.3