X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fsemaphore.h;h=28c3b3d72cb8f009fd4474cfa73ab586db1a1d02;hp=b060947b57e0d0aaf661b9a04c1141f4c3f3d3dc;hb=HEAD;hpb=7292f4413397b7f2e4689f7597f4b9e73435352e diff --git a/source/core/semaphore.h b/source/core/semaphore.h index b060947..f504289 100644 --- a/source/core/semaphore.h +++ b/source/core/semaphore.h @@ -1,40 +1,26 @@ -/* -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 "mutex.h" -#include "types.h" -#include "../time/timedelta.h" +#ifndef MSP_CORE_SEMAPHORE_H_ +#define MSP_CORE_SEMAPHORE_H_ + +#include +#include "mspcore_api.h" +#include "noncopyable.h" namespace Msp { -class Semaphore +class MSPCORE_API Semaphore: private NonCopyable { -public: -#ifndef WIN32 - Semaphore() { pthread_cond_init(&sem, 0); } - int signal() { MutexLock l(mutex); return pthread_cond_signal(&sem); } - int broadcast() { MutexLock l(mutex); return pthread_cond_broadcast(&sem); } - int wait() { MutexLock l(mutex); return pthread_cond_wait(&sem, &mutex.mutex); } - int wait(const Time::TimeDelta &); - ~Semaphore() { pthread_cond_destroy(&sem); } -#else - Semaphore() { sem=CreateSemaphore(0, 0, 32, 0); } - int signal() { return !ReleaseSemaphore(sem, 1, 0); } - int broadcast() { return !ReleaseSemaphore(sem, 32, 0); } - int wait() { return WaitForSingleObject(sem, INFINITE)==WAIT_OBJECT_0; } - int wait(const Time::TimeDelta &); - ~Semaphore() { CloseHandle(sem); } -#endif private: -#ifndef WIN32 - Mutex mutex; -#endif - SemaphoreHandle sem; + struct Private; + + Private *priv = nullptr; + +public: + Semaphore(unsigned); + ~Semaphore(); + + void signal(); + void wait(); + bool wait(const Time::TimeDelta &); }; }