]> git.tdb.fi Git - libs/core.git/blob - source/semaphore.h
Add files
[libs/core.git] / source / 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
12 namespace Msp {
13
14 class Semaphore
15 {
16 public:
17         Semaphore() { pthread_cond_init(&cond, 0); }
18         Mutex &get_mutex() { return mutex; }
19         int   signal()     { return pthread_cond_signal(&cond); }
20         int   broadcast()  { return pthread_cond_broadcast(&cond); }
21         int   wait()       { return pthread_cond_wait(&cond, &mutex.mutex); }
22         ~Semaphore()       { pthread_cond_destroy(&cond); }
23 private:
24         Mutex mutex;
25         pthread_cond_t cond;
26 };
27
28 }
29
30 #endif