X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fsemaphore.h;fp=source%2Fcore%2Fsemaphore.h;h=75c51e6a424716deee151e3bedfd7eb80342e006;hp=0000000000000000000000000000000000000000;hb=e1ea831a640fba534e7e42e399f04cdf681ef8d3;hpb=0bcb8d4d6f33cbdad7b921cac787740bfe8e212e diff --git a/source/core/semaphore.h b/source/core/semaphore.h new file mode 100644 index 0000000..75c51e6 --- /dev/null +++ b/source/core/semaphore.h @@ -0,0 +1,34 @@ +/* +This file is part of libmspframework +Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ +#ifndef MSP_FRAMEWORK_SEMAPHORE_H_ +#define MSP_FRAMEWORK_SEMAPHORE_H_ + +#include +#include "mutex.h" +#include "../time/timedelta.h" + +namespace Msp { + +class Semaphore +{ +public: +#ifndef WIN32 + Semaphore() { pthread_cond_init(&cond, 0); } + //Mutex &get_mutex() { return mutex; } + int signal() { MutexLock l(mutex); return pthread_cond_signal(&cond); } + int broadcast() { MutexLock l(mutex); return pthread_cond_broadcast(&cond); } + int wait() { mutex.lock(); return pthread_cond_wait(&cond, &mutex.mutex); } + int wait(const Time::TimeDelta &); + ~Semaphore() { pthread_cond_destroy(&cond); } +#endif +private: + Mutex mutex; + pthread_cond_t cond; +}; + +} + +#endif