]> git.tdb.fi Git - libs/core.git/blob - source/core/semaphore.h
75c51e6a424716deee151e3bedfd7eb80342e006
[libs/core.git] / source / core / semaphore.h
1 /*
2 This file is part of libmspframework
3 Copyright © 2006  Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
5 */
6 #ifndef MSP_FRAMEWORK_SEMAPHORE_H_
7 #define MSP_FRAMEWORK_SEMAPHORE_H_
8
9 #include <pthread.h>
10 #include "mutex.h"
11 #include "../time/timedelta.h"
12
13 namespace Msp {
14
15 class Semaphore
16 {
17 public:
18 #ifndef WIN32
19         Semaphore()        { pthread_cond_init(&cond, 0); }
20         //Mutex &get_mutex() { return mutex; }
21         int   signal()     { MutexLock l(mutex); return pthread_cond_signal(&cond); }
22         int   broadcast()  { MutexLock l(mutex); return pthread_cond_broadcast(&cond); }
23         int   wait()       { mutex.lock(); return pthread_cond_wait(&cond, &mutex.mutex); }
24         int   wait(const Time::TimeDelta &);
25         ~Semaphore()       { pthread_cond_destroy(&cond); }
26 #endif
27 private:
28         Mutex mutex;
29         pthread_cond_t cond;
30 };
31
32 }
33
34 #endif