1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#ifndef MT_CONDITION_H
#define MT_CONDITION_H
#include "base.h"
#include "mutex.h"
#include <pthread.h>
namespace mt
{
class condition
{
MT_PREVENT_COPY(condition)
public:
typedef condition this_type;
typedef void base_type;
condition(void)
{
pthread_cond_init(&(this->c), 0);
}
~condition(void)
{
pthread_cond_destroy(&(this->c));
}
void signal(void)
{
pthread_cond_signal(&(this->c));
}
void broadcast(void)
{
pthread_cond_broadcast(&(this->c));
}
void wait(mutex & m)
{
pthread_cond_wait(&(this->c), &(m.m));
}
private:
pthread_cond_t c;
};
}
#endif // MT_CONDITION_H
|