]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/semaphore.h
Use vectors for storage in Poller
[libs/core.git] / source / core / semaphore.h
index a7cdff7371d4f301468ff42da669cea6daa5db26..9ab25f2d48306471bcfd63b0439e501ee5f0fc37 100644 (file)
@@ -1,41 +1,25 @@
-/*
-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 <msp/time/timedelta.h>
+#include "noncopyable.h"
 
 namespace Msp {
 
-class Semaphore
+class Semaphore: private NonCopyable
 {
-public:
-#ifndef WIN32
-       Semaphore()        { pthread_cond_init(&sem, 0); }
-       //Mutex &get_mutex() { return mutex; }
-       int   signal()     { MutexLock l(mutex); return pthread_cond_signal(&sem); }
-       int   broadcast()  { MutexLock l(mutex); return pthread_cond_broadcast(&sem); }
-       int   wait()       { mutex.lock(); 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;
+
+public:
+       Semaphore(unsigned);
+       ~Semaphore();
+
+       void signal();
+       void wait();
+       bool wait(const Time::TimeDelta &);
 };
 
 }