X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fsemaphore.h;h=3f2cc974a455855c35246f7abc10d12d1993e709;hb=a1d6fa071280123f282c1bac3b68008672401024;hp=c55553a6f31d9ffd02b23040621ebb87337feff0;hpb=521cf1db00f8ce2d9f9494dca503d6c17d89ac2f;p=libs%2Fcore.git diff --git a/source/core/semaphore.h b/source/core/semaphore.h index c55553a..3f2cc97 100644 --- a/source/core/semaphore.h +++ b/source/core/semaphore.h @@ -4,47 +4,30 @@ This file is part of libmspcore Copyright © 2006 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ + #ifndef MSP_CORE_SEMAPHORE_H_ #define MSP_CORE_SEMAPHORE_H_ #include "mutex.h" -#include "types.h" #include "../time/timedelta.h" namespace Msp { class Semaphore { -public: - Semaphore(); - Semaphore(Mutex &); - int signal(); - int broadcast(); - int wait(); - int wait(const Time::TimeDelta &); - Mutex &get_mutex() { return *mutex; } - ~Semaphore(); private: - Mutex *mutex; - bool own_mutex; - SemaphoreHandle sem; -#ifdef WIN32 - unsigned count; -#endif - - void init(); -}; + struct Private; -#ifndef WIN32 -inline int Semaphore::signal() -{ return pthread_cond_signal(&sem); } + Private *priv; -inline int Semaphore::broadcast() -{ return pthread_cond_broadcast(&sem); } +public: + Semaphore(unsigned); + ~Semaphore(); -inline int Semaphore::wait() -{ return pthread_cond_wait(&sem, &mutex->mutex); } -#endif + void signal(); + void wait(); + bool wait(const Time::TimeDelta &); +}; }